【发布时间】:2021-11-16 01:13:50
【问题描述】:
这可能是一个显而易见的问题,但我有一列包含一系列数字。我想遍历整个列以获取它们的值。我正在使用此代码查找列的最后一行:
Cells(Rows.Count, 4).End(xlUp).Row
如何获取从列中第一个数字开始到最后一个数字的值?
【问题讨论】:
这可能是一个显而易见的问题,但我有一列包含一系列数字。我想遍历整个列以获取它们的值。我正在使用此代码查找列的最后一行:
Cells(Rows.Count, 4).End(xlUp).Row
如何获取从列中第一个数字开始到最后一个数字的值?
【问题讨论】:
Sub loopThroughRange()
Dim col As Integer
Dim colRng As Range, rCell As Range
col = 4
' Option 1: Select from the top to bottom before first blank cell
Set colRng = Range(Cells(1, col), Cells(1, col).End(xlDown))
'colRng.Select
' Option 2: Select from the first value to last value in column (includes blanks)
'Set colRng = Range(Cells(1, col), Cells(Rows.Count, col).End(xlUp))
'colRng.Select
For Each rCell In colRng
Debug.Print rCell.Value
Next rCell
End Sub
【讨论】: