Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Variable within a range?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Variable within a range?

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

mes C." wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Variable within a range?

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.
--

Toby Erkson
http://excel.icbm.org/


"James C." wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Range to VLOOKUP as a Variable (range in another file) LuisE Excel Programming 3 December 2nd 07 03:22 PM
select range and put range address in variable [email protected] Excel Programming 2 January 25th 06 01:28 AM
Macro to copy a specified range to a variable range SWT Excel Programming 4 October 21st 05 08:24 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 03:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"