選択されているセル範囲は Selection で表される。
例えば、セル C5〜F9 を選択し、下記コードを実行すると、
For i = 1 To Selection.Count Selection(i) = "Selection (" & i & ")" Next
下図のようになる。
以下は、デバッグウィンドウで確認した結果。
実行したコード | 結果(戻り値) | 備考 |
---|---|---|
Selection.Address | $C$5:$F$9 | 選択範囲 C5:F9 |
Selection.Count | 20 | 選択されているセルの数 |
Selection.Cells(1).Row | 5 | 左上のセルの行番号 |
Selection.Cells(1).Column | 3 | 左上のセルの列番号 |
Selection.Cells(Selection.Count).Row | 9 | 右下のセルの行番号 |
Selection.Cells(Selection.Count).Column | 6 | 右下のセルの列番号 |