Name Define in vba as variable

jfarc

Active Member
Joined
Mar 30, 2007
Messages
308
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?
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,093
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Code:
Range(Range("A1"), Range("A1").End(xlDown)).Name = "VIN2"
should do it.
 

jfarc

Active Member
Joined
Mar 30, 2007
Messages
308
I'll give that a shot. I think I know what your mean now.

(Wasn't getting it at first)
 

jfarc

Active Member
Joined
Mar 30, 2007
Messages
308

ADVERTISEMENT

Thanks Bob, that was perfect!

(did you have to make it look so easy, though????) ;)
 

BobUmlas

Well-known Member
Joined
Mar 14, 2002
Messages
1,181
Sorry -- should have been:
Selection.name="VIN2"
originally I made it a local name.
 

jfarc

Active Member
Joined
Mar 30, 2007
Messages
308

ADVERTISEMENT

Well that's even easier.

I tried the first way you gave and it worked fine. What is the difference between the two?
 

BobUmlas

Well-known Member
Joined
Mar 14, 2002
Messages
1,181
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.
 

jfarc

Active Member
Joined
Mar 30, 2007
Messages
308
Oh, I definitely want it global. It'll be called from other sheets.

Thanks again.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,804
Messages
5,598,158
Members
414,214
Latest member
marketingnumbersguy

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
Top