Variables in a Range statement

  • Thread starter Thread starter ChuckM
  • Start date Start date
C

ChuckM

How can I insert variables in a range statement. For instance: I
have looked down column j for a particular value and have found it in
row m. If I copy everything from the top (A1) up thru row m I can use:

Sheets("Sheet1").Range("a1:j" & m).Copy ActiveSheet.Range("A4")

where I can append the row range m to 'j'. But in general, how can
I use variables for the arguements in the Range statement.
thanks
chuck
 
Dim i as long, m as long
Dim sA as string, sB as String
Dim sStr as String
i = 1
m = 20
sStr = "A" & i & ":" & "J" & m

Range(sStr).Select

sA = "AA"
sB = "AK"
sStr = sA & i & ":" & sB & m
Range(sStr).Select

Generally if you are going to use variables for row and column locations, it
is easier to use Cells
Dim rw as long, rw1 as long, col as long, col1 as long
rw = 1
col = 5
rw1 = 20
col1 = 8
Range(Cells(rw,col),Cells(rw1,col1)).Select
 
Back
Top