Variable within a range?

J

James C.

Does someone know how to insert a variable into a range.

For instance my original code is:
Sheets("Annual Data").Select
Range("BR7:CP7").Select
Selection.Copy
Range("BR8:CP25000").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

However, I don't want to copy down to row 25000, instead I have a variable
called maxRow. I would like to insert this into the code but I don't know how
to do this. The column would stay the same just the 25000 would be relplaced
with maxRow. The new code would look like

Sheets("Annual Data").Select
Range("BR7:CP7").Select
Selection.Copy
Range("BR8:CP[maxRow]").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
 
M

Mike

This might work
maxRow= Range("CP" & Rows.Count).End(xlUp).Row
Range("BR8:CP" & maxRow).Select
 
A

Air_Cooled_Nut

You almost have it :)
Old: Range("BR8:CP[maxRow]").Select
New: Range("BR8:CP" & maxRow).Select
If maxRow should be a Long data type variable.
 

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