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 |
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/ . |
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 |
All times are GMT +1. The time now is 10:49 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com