Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Passing cell addressess to variables to be use in range
I have passing two cell address references from a spreadsheet to tw
variables in VBA. I am then trying to use these variables in a rang for copying purposes. I am not incorpoating them properly into Rang Statment. What am I doing wrong? Thanks Dim FirstCell As String Dim LastCell As String FirstCell = Range("BeginRangeCell") LastCell = Range("EndRangeCell") Sheets("Import Sheet").Select Range("FirstCell:LastCell").Select Selection.Copy End Su -- Message posted from http://www.ExcelForum.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Passing cell addressess to variables to be use in range
Variables should not be enclosed in quotation marks.
When using Range, change: Range("FirstCell:LastCell").Select To: Range(FirstCell, LastCell).Select or if you prefer, you could concatinate them using the "&" character like: Range(FirstCell & ":" & LastCell).Select Likewise: FirstCell = Range("BeginRangeCell") LastCell = Range("EndRangeCell") should be: FirstCell = Range(BeginRangeCell) LastCell = Range(EndRangeCell) Consult the VBA help on Range for more examples. Regards, Kris -----Original Message----- I have passing two cell address references from a spreadsheet to two variables in VBA. I am then trying to use these variables in a range for copying purposes. I am not incorpoating them properly into Range Statment. What am I doing wrong? Thanks Dim FirstCell As String Dim LastCell As String FirstCell = Range("BeginRangeCell") LastCell = Range("EndRangeCell") Sheets("Import Sheet").Select Range("FirstCell:LastCell").Select Selection.Copy End Sub --- Message posted from http://www.ExcelForum.com/ . |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Passing cell addressess to variables to be use in range
Figured it out.
Sub Macro3() Dim FirstCell As String Dim LastCell As String FirstCell = Range("BeginRangeCell") LastCell = Range("EndRangeCell") Sheets("Import Sheet").Select Range(FirstCell & ":" & LastCell).Select Selection.Copy End Su -- Message posted from http://www.ExcelForum.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VBA - passing Variables to subroutines | Excel Discussion (Misc queries) | |||
Passing Variables | Excel Discussion (Misc queries) | |||
VBA passing variables through a function | Excel Discussion (Misc queries) | |||
Passing variables between a form and macro | New Users to Excel | |||
Passing Variables | Excel Programming |