ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variables in a Range statement (https://www.excelbanter.com/excel-programming/285461-variables-range-statement.html)

ChuckM[_2_]

Variables in a Range statement
 
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

Tom Ogilvy

Variables in a Range statement
 
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

--
Regards,
Tom Ogilvy


"ChuckM" wrote in message
m...
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





All times are GMT +1. The time now is 01:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com