选择填充行

问题描述 投票:0回答:1

我有一个包含固定列和行的范围(A1 到 C15)(不是表格)

我想选择第 1 列被填充的行(编号)。可以用VBA做吗?

提前致谢

根据单元格选择填充行

excel vba macros
1个回答
0
投票
  • 在大多数情况下,您不需要
    Select
    使用VBA代码

如何避免在 Excel VBA 中使用 Select

Sub Demo()
    Dim lastRow As Long, oSht As Worksheet
    Set oSht = ActiveSheet ' modify as needed
    lastRow = oSht.Cells(oSht.Rows.Count, "A").End(xlUp).Row
    If lastRow > 1 Then
        ' Select the first 3 Cols
        oSht.Range("A2:C" & lastRow).Select
        ' Select rows
        ' oSht.Range("2:" & lastRow).Select
    End If
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.