管理人Kのひとりごと

デジモノレビューやプログラミングや写真など

最下行アドレスを取得する(ExcelVBA)

カレントセルの列の、最下行アドレス(値の入力された最下行のアドレス)を取得する。

Option Explicit

Sub カレントセル列の最後尾アドレスを取得する()
    Dim currentRange As Range
    Dim maxRowNum As Integer
    Dim tmpColumnName As String
    Dim columnName As String
    
    Set currentRange = Cells(Rows.Count, ActiveCell.Column)
    maxRowNum = currentRange.End(xlUp).Row
    tmpColumnName = currentRange.Address(True, False)
    Set currentRange = Nothing
    
    columnName = Left(tmpColumnName, InStr(tmpColumnName, "$") - 1)
    Debug.Print columnName & maxRowNum
End Sub