アナログCPU:5108843109

ゲームと音楽とプログラミング(酒と女とロックンロールのノリで)

('ω') < イザユケエンジニャー

ワークシートの最大行数、最大列数を取得

最大行数は Rows.Count
最大列数は Columns.Count
で取得できます。

' 使用例(1):「Sheet1」シートの全セルのデータや書式設定を削除
With ThisWorkbook.Sheets("Sheet1")
    Range(Cells(1, 1), Cells(Rows.Count, Columns.Count)).Clear
End With

' 使用例(2):可変値が範囲外にならないようなエラーチェック
Dim lRow As Long
Dim lCol As Long
lRow = ~~
lCol = ~~
If (0 < lRow And lRow <= Rows.Count) And (0 < lCol And lCol <= Columns.Count) Then
    ThisWorkbook.Sheets("Sheet1").Cells(lRow, lCol).Value = "hoge"
Else
    MsgBox ("範囲外やで")
End If