selecting more than one cell

R

RobcPettit

Hi, Im trying to select more than one cell depending on a value in
another cell.
For i = 3 To 33

If Range("d" & i) = "True" Then
Range("as" & i).Select
End If
Next i

there could be several cells, so I want to select them all, or they
may alternate. Simular to using the control button when selecting
various cells. 99% of the time they will be grouped together, so Im
guessing I could select the first cell the offset to select the next.
I dont know though how to select more than one cell this way.
Regards Robert
 
R

Rick Rothstein \(MVP - VB\)

First, we need to know what is actually in the cells you are trying to
match... is it Excel's TRUE or is it really the text "True"? If text, is the
text always an upper case T followed by lower case letters?

Rick
 
C

Charlie

Separate the ranges with commas

Range("A1,B2:B4,C3").Select

I don't know if there's a limit on the number of ranges you can specify in
this manner.
 
D

Dave Peterson

Dim myRng as range
dim i as long
set myrng = nothing
for i = 3 to 33
if activesheet.cells(i,"D").value = true then
if myrng is nothing then
set myrng = activesheet.cells(i,"D")
else
set myrng = union(myrng, activesheet.cells(i,"D"))
end if
end if
next i

if myrng is nothing then
msgbox "Nothing to select!"
else
myrng.select
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top