Selecting a Range Using a Variable

  • Thread starter Thread starter Bob J.
  • Start date Start date
B

Bob J.

Does anybody know what the marco command(s) are for
selecting a range of cells in a column using a variable?
 
yes, hope this example helps:

Sub SelectRows2To5InCol()
Dim Col
Col = 3
Range(Cells(2, Col), Cells(5, Col)).Select
End Sub

regards, Mika
 
Bob,

If its the row, its easy

Range("A" & startRow & ":B" & endRow).Select

Columns are just as easy if your variable is a letter, but if it is a
number, you either
convert to a letter
Range("A1:" & Chr(startcol + 64) & "10").Select
or use Cells
Range("A1", Cells(10, startcol)).Select
 
Thanks! This is exactly what I was looking for.

-----Original Message-----
yes, hope this example helps:

Sub SelectRows2To5InCol()
Dim Col
Col = 3
Range(Cells(2, Col), Cells(5, Col)).Select
End Sub

regards, Mika


variable?


.
 
Thanks! This is exactly what I was looking for.

-----Original Message-----
Range(Cells(TopLeftRow,TopLeftColumn),Cells (BottomRightRow,BottomRightColumn
)).Select



Note that you don't need to 'select' a range to use it..
With
Range(Cells(TopLeftRow,TopLeftColumn),Cells (BottomRightRow,BottomRightColumn
))
.Clear
.Interior.Colorindex=3
End With

--
Patrick Molloy
Microsoft Excel MVP
----------------------------------
variable?


.
 
Back
Top