0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VBAで「指定の範囲の中の」1行を指定する一番簡単で一番やさしい方法

Last updated at Posted at 2025-09-14
rng.Rows(1)

VBAで「指定の範囲の中の1行」を指定する方法は

WorkSheet.Rowsプロパティー

ではなく、

WorkSheet.Range.Rowsプロパティー

です。
恐ろしい事に、どの本にも、どの記事にも書いてありません。

Set rng = ws.Range("C10:F100")

rng.Rows(1)

です。
これでRange("C10:F10")の範囲だけを指定する事が出来ます。

ws.Rows(1)だと、WorkSheet.Rowsプロパティーなので、
指定のシートの1行目の全ての列、つまり

ws.Range("A1:XFD1")

まで指定されます。

しかし、rng.Rows(1)だと、
WoorkSheet.「Range」.Rowsプロパティーなので、指定した範囲での指定の行が指定できます。
なので、

For r = 1 To rng.Rows.Count 'これで指定の範囲の行数を取得できます。
rng.Rows(r) 'これで「指定の範囲内」の行を指定
rng.Cells(r,1).Value 'これで指定の範囲内の単一セルの値を取得

です。
私もこれを知るまでは律儀にRange("C" & r & ":F" & r)や、Range("C" & r & ":F" & r)やOffsetなどで指定していました。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?