PDA

View Full Version : Solved: Selecting a Range of Rows



Opv
07-22-2010, 05:35 PM
What is the proper syntax for selecting a multiple rows (both contiguous and non-contiguous) with Rows()?

geekgirlau
07-22-2010, 06:29 PM
Do you actually want to select them, or just to perform some kind of action on them? Most of the time selecting anything in vba is not required.

Opv
07-22-2010, 06:33 PM
Do you actually want to select them, or just to perform some kind of action on them? Most of the time selecting anything in vba is not required.

"Select" was the wrong word. I was just talking about how to reference rows using Rows() to define the range on which I want to perform an action. For example, rows 5-50 as opposed to rows 5,15,25,50, etc.

Also, when I type in "Rows(" in the code editor, the system displays "rowindex, columnindex" so I get confused whether I can enter column information or whether Rows is just limited to row numbers.

geekgirlau
07-22-2010, 07:46 PM
Depends on what you want to do, but you can use something like:


Dim rng As Range

Set rng = Range(shData.Rows(1), shData.Rows(50))

rng.Interior.ColorIndex = 4



or


Dim i As Long

For i = 1 To 50
shData.Rows(i).Calculate
Next i

YasserKhalil
07-23-2010, 02:44 AM
What is the proper syntax for selecting a multiple rows (both contiguous and non-contiguous) with Rows()?

Rows("1:50")

Range("5:5,15:15,50:50")

Opv
07-23-2010, 02:54 AM
Rows("1:50")
Range("5:5,15:15,50:50")

Thanks, but the second example (using Range) is resulting in an error "wrong number of arguments."

YasserKhalil
07-23-2010, 03:06 AM
Dim rng As Range
Set rng = Range("5:5,15:15,50:50")
rng.Interior.ColorIndex = 4

Opv
07-23-2010, 03:12 AM
Dim rng As Range
Set rng = Range("5:5,15:15,50:50")
rng.Interior.ColorIndex = 4


Now that worked. When I just tried:


Range("5:5",15:15,50:50").select


I got an error. Oh well, thanks.

Opv

mdmackillop
07-24-2010, 01:43 AM
When I just tried:


Range("5:5",15:15,50:50").select


I got an error.
That's because of the extra "

Opv
07-24-2010, 08:19 AM
That's because of the extra "

Thanks.