计算单元格,复制400个单元格,更新单元格总数,继续处理,直到计数为0



这是我想到的过程:

  1. 计算列A中包含数据的所有单元格(我正在考虑"xlUp"?)并将该数字设置为变量。
  2. 选择A列的前400个单元格(从A2开始),并用黄色填充它们。
  3. 复制该数据(将数据粘贴到另一个程序中((我们调用快捷键"!*Z"))。
  4. 从总细胞数变量中减去400。
  5. 在A列中选择第二个400个单元格(从A402开始)
  6. 填充颜色为黄色
  7. 复制数据(!*Z)。
  8. 从更新的细胞计数变量中减去400。
  9. 重复,直到最后一个数据单元格被复制并填充颜色。

请帮忙就太好了。
我觉得我在这件事上兜圈子太久了。是时候问问专家了。谢谢你!

批处理范围

  • 这是我对适用于您的案例的建议帖子的快速(简短)看法。如果你发现了改进,请务必分享。
Option Explicit
Sub BatchRange()

Const sfRow As Long = 2
Const sCol As String = "A"
Const Batch As Long = 400

' Create a reference to the First Cell.
Dim sfCell As Range: Set sfCell = Sheet1.Cells(sfRow, sCol)
' Calculate the last row.
Dim slRow As Long
slRow = Sheet1.Cells(Sheet1.Rows.Count, sCol).End(xlUp).Row

Dim srCount As Long: srCount = slRow - sfRow + 1
Dim bCount As Long: bCount = Int(srCount / Batch) + 1

Dim srg As Range
Dim b As Long
Dim r As Long

For b = 1 To bCount

If b = bCount Then
r = srCount Mod Batch
Else
r = Batch
End If

If r > 0 Then
' Create a reference to the current Column Range.
Set srg = sfCell.Resize(r)


' Do your stuff
' e.g.:
Debug.Print sfCell.Address(0, 0), srg.Address(0, 0)
' or:
srg.Interior.Color = vbYellow


' Create a reference to the next First Cell.
Set sfCell = sfCell.Offset(r)
End If

Next b

End Sub

最新更新