Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy range to a variable.
Is it possible to copy a range of cells and set them equal to a variable?
Something like this: Cells(1, 1).Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy x = selection Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy range to a variable.
this should be all you need
rng = Range("A1", range("A1").End(xlToRight)) open the immediate window in the vb editor (control G) and paste the above line and press enter then enter this line and press enter and it should display the range ?rng.address -- Gary Keramidas Excel 2003 "Brian S" wrote in message ... Is it possible to copy a range of cells and set them equal to a variable? Something like this: Cells(1, 1).Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy x = selection Thanks |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy range to a variable.
You can set them to a Range variable as below
Dim myRange As Range Set myRange = Range("A1").Resize(Range("A1").End(xlDown).Row, _ Range("A1").End(xlToRight).Column) myRange.Select -- Jacob "Brian S" wrote: Is it possible to copy a range of cells and set them equal to a variable? Something like this: Cells(1, 1).Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy x = selection Thanks |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy range to a variable.
sorry missed the 2nd part of your selection
-- Gary Keramidas Excel 2003 "Gary Keramidas" <GKeramidasAtMSN.com wrote in message ... this should be all you need rng = Range("A1", range("A1").End(xlToRight)) open the immediate window in the vb editor (control G) and paste the above line and press enter then enter this line and press enter and it should display the range ?rng.address -- Gary Keramidas Excel 2003 "Brian S" wrote in message ... Is it possible to copy a range of cells and set them equal to a variable? Something like this: Cells(1, 1).Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy x = selection Thanks |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy range to a variable.
here is another way, jacob's is shorter
Dim rng2 As Range Set rng2 = Range(Range("A1", Range("A1").End(xlDown)), Range(Range("A1").End(xlToRight), _ Range("A1").End(xlToRight).End(xlDown))) rng2.Select -- Gary Keramidas Excel 2003 "Gary Keramidas" <GKeramidasAtMSN.com wrote in message ... sorry missed the 2nd part of your selection -- Gary Keramidas Excel 2003 "Gary Keramidas" <GKeramidasAtMSN.com wrote in message ... this should be all you need rng = Range("A1", range("A1").End(xlToRight)) open the immediate window in the vb editor (control G) and paste the above line and press enter then enter this line and press enter and it should display the range ?rng.address -- Gary Keramidas Excel 2003 "Brian S" wrote in message ... Is it possible to copy a range of cells and set them equal to a variable? Something like this: Cells(1, 1).Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy x = selection Thanks |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy range to a variable.
Since you are using xlDown and xlToRight, wouldn't this be equivalent to the
Set statement you posted? Set myRange = Range("A1").CurrentRegion -- Rick (MVP - Excel) "Jacob Skaria" wrote in message ... You can set them to a Range variable as below Dim myRange As Range Set myRange = Range("A1").Resize(Range("A1").End(xlDown).Row, _ Range("A1").End(xlToRight).Column) myRange.Select -- Jacob "Brian S" wrote: Is it possible to copy a range of cells and set them equal to a variable? Something like this: Cells(1, 1).Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy x = selection Thanks |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy range to a variable.
Gary, even this might be what the OP is looking for ()..
Activesheet.usedrange.select OR Dim myRange as Range Set myRange = ActiveSheet.UsedRange -- Jacob "Gary Keramidas" wrote: here is another way, jacob's is shorter Dim rng2 As Range Set rng2 = Range(Range("A1", Range("A1").End(xlDown)), Range(Range("A1").End(xlToRight), _ Range("A1").End(xlToRight).End(xlDown))) rng2.Select -- Gary Keramidas Excel 2003 "Gary Keramidas" <GKeramidasAtMSN.com wrote in message ... sorry missed the 2nd part of your selection -- Gary Keramidas Excel 2003 "Gary Keramidas" <GKeramidasAtMSN.com wrote in message ... this should be all you need rng = Range("A1", range("A1").End(xlToRight)) open the immediate window in the vb editor (control G) and paste the above line and press enter then enter this line and press enter and it should display the range ?rng.address -- Gary Keramidas Excel 2003 "Brian S" wrote in message ... Is it possible to copy a range of cells and set them equal to a variable? Something like this: Cells(1, 1).Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy x = selection Thanks . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Select and copy a variable range | Excel Programming | |||
VBA help to copy variable range | Excel Discussion (Misc queries) | |||
Copy a Variable range | Excel Programming | |||
Copy Variable Range to New Worksheet | Excel Programming | |||
Macro to copy a specified range to a variable range | Excel Programming |