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 5 years have passed since last update.

range指定ではなくActivecell指定で複数の連続していない(飛び石)位置のセルを選択する方法

Posted at

ExcelVBAで複数の連続していないセルを選択する方法を記載する。
rangeで指定すればこれは割と簡単で、
Range(range(A1), ActiveCell.Offset(B3)).Select

のような構文で実現することができる。
しかしこれを応用してActivecellで同じ構文を作ると失敗する
Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(2, 3)).Select

このようにすると範囲選択が連続するすべてのセルになってしまう。
つまりoffset(0,1)から(2,3)の間にある全てのセルが選択されてしまう。
offset(0,1)と(2,3)だけを選択したい場合は以下のようにする
Application.Union(ActiveCell.Offset(0, 1), ActiveCell.Offset(2,3)).Select

これで実現可能。
この後に
Selection.Copy
Selection.PasteSpecial
activecell.offset(0,1)

あたりを打ち込めば行ごとに自動でコピー&ペーストを繰り返せるあはずだ。

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?