Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
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
VBA - passing Variables to subroutines Madduck Excel Discussion (Misc queries) 12 September 19th 08 03:20 AM
Passing Variables Jeff Excel Discussion (Misc queries) 1 November 4th 05 06:46 PM
VBA passing variables through a function Jeff Excel Discussion (Misc queries) 2 November 3rd 05 11:23 PM
Passing variables between a form and macro David New Users to Excel 1 October 5th 05 04:42 AM
Passing Variables Royce[_2_] Excel Programming 1 November 20th 03 02:16 PM


All times are GMT +1. The time now is 05:33 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"