Skip to content

Instantly share code, notes, and snippets.

@nobrinskii
Created March 16, 2012 05:29
Show Gist options
  • Save nobrinskii/2048655 to your computer and use it in GitHub Desktop.
Save nobrinskii/2048655 to your computer and use it in GitHub Desktop.
[vba/excel] 指定された行の、入力された最終列番号を取得する
'-------------------------------------------------------------------------------
'指定された行の、入力された最終列番号を取得する
'-------------------------------------------------------------------------------
'【引数】対象シート、対象の行番号
'【戻り値】列番号
'【備考】シートの右端から左方向に検索して、最初に値が入ったセルの列番号を返す。
Private Function GetLastColNumber(shtTarget As Worksheet, lngRow As Long) As Integer
Dim intMaxCol As Integer
Dim intLastCol As Integer
With shtTarget
intMaxCol = .Cells().Columns.Count
intLastCol = .Cells(lngRow, intMaxCol).End(xlToLeft).Column
End With
GetLastColNumber = intLastCol
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment