シートの最後の行または列を取得するには、いつでも Sheet.UsedRange.Rows.Count または Sheet.UsedRange.Columns.Count を実行できます。
これにより、特定のセルまたは範囲の列を取得できます。
Split(Columns(Cells(1, 30).Column).Address(False, False), ":")
セルの列:
Sub Example()
Dim LR As Long
Dim Col() As String
LR = Cells(Rows.Count, "A").End(xlUp).Row
Col = Split(Columns(Cells(1, 30).Column).Address(False, False), ":")
MsgBox ("The last non-used cell is in column " & Col(0) & " row " & LR)
End Sub
範囲の列:
Sub Example()
Dim LR As Long
Dim Col() As String
LR = Cells(Rows.Count, "A").End(xlUp).Row
Col = Split(Columns(Range("A:C").Columns.Count).Address(False, False), ":")
MsgBox ("The last non-used cell is in column " & Col(0) & " row " & LR)
End Sub
シートの最後の列:
Sub Example()
Dim LR As Long
Dim Col() As String
LR = Cells(Rows.Count, "A").End(xlUp).Row
Col = Split(Columns(ActiveSheet.UsedRange.Columns.Count).Address(False, False), ":")
MsgBox ("The last non-used cell is in column " & Col(0) & " row " & LR)
End Sub
-編集-
最後の未使用の列:
Sub Example()
Dim LR As Long
Dim Col() As String
LR = Cells(Rows.Count, "A").End(xlUp).Row
'Col = Split(Columns(ActiveSheet.UsedRange.Columns.Count + 1).Address(False, False), ":")
'Alternative method to get column number
Col = Split(Columns(ActiveSheet.Columns.Count).End(xlToLeft).Address(False, False), ":")
MsgBox ("The last non-used cell is in column " & Col(0) & " row " & LR)
End Sub
最後の未使用行:
Sub Example()
Dim LR As Long
Dim Col() As String
LR = ActiveSheet.UsedRange.Rows.Count + 1
Col = Split(Columns(ActiveSheet.UsedRange.Columns.Count + 1).Address(False, False), ":")
MsgBox ("The last non-used cell is in column " & Col(0) & " row " & LR)
End Sub