返回列表 上一主題 發帖

[發問] 如何用vba知道選取區域作用的儲存格&欄&列的首欄列及尾欄列位置

選取區域作用的儲存格&欄&列的首欄列及尾欄列位置
debug.print Selection.address
or
debug.print Selection.address(0,0)

TOP

接入您的代碼試看, 但由於不知篩選的實際區域,下面代碼是以[a1]為準
Sub zz()
If ActiveSheet.FilterMode = True Then
    Set rng = [a1].CurrentRegion
    zr = rng.Rows.Count
    zc = rng.Columns.Count
    For i = 2 To zr
        If rng.Cells(i, 1).RowHeight > 0 Then Exit For
    Next
MsgBox rng.Cells(i, 1).Address(0, 0) & ":" & rng.Cells([a1].End(4).Row, zc).Address(0, 0)
End If
End Sub

TOP

Sub zz()
If ActiveSheet.FilterMode = True Then
    Set rng = [a1].CurrentRegion
    zr = rng.Rows.Count
    zc = rng.Columns.Count
    For i = 2 To zr
        If rng.Cells(i, 1).RowHeight > 0 Then Exit For
    Next
MsgBox rng.Cells(i, zc).Address(0, 0) & ":" & rng.Cells([a1].End(4).Row, zc).Address(0, 0)
End If
End Sub

TOP

        靜思自在 : 道德是提昇自我的明燈,不該是呵斥別人的鞭子。
返回列表 上一主題