VBA Cell 最終列の取得

最終列の取得

指定した行の最終列を取得します。
例は、1行目(Row=1)で取得

'最大列から左方向へ空でないセルを探す
MaxCol = Cells(1,Columns.Count).End(xlToLeft).Column

表の最終列を取得

以下の様な表の最終列を取得する場合
CurrentRegion()関数を使用します

MaxCol = Range("B3").CurrentRegion(Range("B3").CurrentRegion.Count).Column