Passing cell addressess to variables to be use in range

  • Thread starter Thread starter ExcelMonkey
  • Start date Start date
E

ExcelMonkey

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

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

Back
Top