Name Define in vba as variable

jfarc

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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,782
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
314
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
314

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
314

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
314
Oh, I definitely want it global. It'll be called from other sheets.

Thanks again.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,025
Messages
5,835,016
Members
430,332
Latest member
Charly_Moon

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