小编m4s*_*nny的帖子

VBA 识别第一行和最后一行数据

我想要第一行和最后一行包含非空白单元格。我的最后一行工作正常,第一行半身像。建议表示赞赏。

Sub idDataRange()

Dim firstRow As Long
Dim lastRow As Long

Sheets("fileNames").Select

' this has been adapted from a Stack overflow answer. lastRow unedited
' first row I changed Up to Down = NOT the solution!
With ActiveSheet
    firstRow = .Range("B" & .Rows.Count).End(xlDown).row
    lastRow = .Range("B" & .Rows.Count).End(xlUp).row
    End With

    MsgBox "the first row is " & firstRow
    MsgBox "last row is " & lastRow

End Sub
Run Code Online (Sandbox Code Playgroud)

excel vba

2
推荐指数
1
解决办法
4万
查看次数

标签 统计

excel ×1

vba ×1