0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

備忘録 - セル・範囲の指定【VBA】

Last updated at Posted at 2021-03-29

セルを指定

ActiveRange '現在アクティブのセルを指定
Range("セル名") ' A1やB5など通常のエクセルのセル名で指定
Cells(行番号、列番号)

'セルのアドレスを表示
Cells(行番号、列番号).Address

範囲の指定

Range("セル名:セル名")

'空白のセルで囲まれた範囲を取得(表を取得したりするのに便利)
Range("セル名").CurrentRegion 'セルは範囲内のどこでも可

シートにある行の数を計算

Rows.Count

シートにある列の数を計算

Columns.Count

表の最終行を取得

'表の中から下に向かって指定する場合
Range("セル名").End(xlDown).Row

'ワークシートの一番下から上へ範囲を特定する場合
Range("列名"&Rows.Count).End(xlUp).Row '列名は、表の中のどの列でも可

'Cellsを使ってワークシートの一番下から上へ範囲を特定する場合
Cells(Rows.Count,行番号).End(xlUp).Row

表の最終列を取得

'表の中から右に向かって指定する場合
Range("セル名").End(xlToRight).Column

'ワークシートの一番右から左へ範囲を特定する場合
Cells(行番号,Columns.Count).End(xlToLeft).Column '行番号は、表の中のどの行でも可

ワークシートの中で値が入っている最後の行を取得する

'セルの種類から特定する方法
Cells.SpecialCells(xlCellTypeLastCell).Row

'ワークシートから特定する方法
ワークシート.UsedRange.Rows.Count
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?