【问题标题】:Looping Through Entire Column using Last Row Code使用最后一行代码循环整个列
【发布时间】:2021-11-16 01:13:50
【问题描述】:

这可能是一个显而易见的问题,但我有一列包含一系列数字。我想遍历整个列以获取它们的值。我正在使用此代码查找列的最后一行:

Cells(Rows.Count, 4).End(xlUp).Row

如何获取从列中第一个数字开始到最后一个数字的值?

【问题讨论】:

标签: excel vba


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 2020-10-20
    相关资源
    最近更新 更多