Name Define in vba as variable

jfarc

Active Member
Joined
Mar 30, 2007
Messages
316
I recorded the following macro:

Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="VIN2", RefersToR1C1:="='SVCHistory'!R1C1:R1189C1"

I select a cell (A1) and then ShiftCtlDown to the end of that list (R1189C1 in the above example). Then I want to Name that Range. The issue is the ending cell will change each time I run the macro

How can I make the (R1189C1) in the above example a variable of the cell selected by the (Selection.End(xlDown)) command?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Code:
Range(Range("A1"), Range("A1").End(xlDown)).Name = "VIN2"
should do it.
 
Upvote 0
I'll give that a shot. I think I know what your mean now.

(Wasn't getting it at first)
 
Upvote 0
Thanks Bob, that was perfect!

(did you have to make it look so easy, though????) ;)
 
Upvote 0
Well that's even easier.

I tried the first way you gave and it worked fine. What is the difference between the two?
 
Upvote 0
First one makes the name local, so it's ONLY known on that sheet; 2nd one makes the name global (aka "normal") and is known in any sheet.
 
Upvote 0
Oh, I definitely want it global. It'll be called from other sheets.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top