Use VBA to name Ranges

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Guest
Hi guys,
I recorded this macro..
ActiveWorkbook.Names.Add Name:="DATABASE2060", RefersToR1C1:= _
"='2060_DB'!R1C1:R8C9"

Now, I am trying to achieve the same result using VBA.

My code

Set LastCell = ActiveSheet.Range("I65536").End(xlUp)
SV_Code = 2060
Reference = "='" & SV_Code & "_DB!R1C1:" & LastCell.Address(ReferenceStyle:=xlR1C1)

ActiveWorkbook.Names.Add Name:="DATABASE2060", RefersToR1C1:= _
Reference

Running the vba code doesn't achieve the same result. Help guys
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
On 2002-03-07 17:13, Anonymous wrote:
Hi guys,
I recorded this macro..
ActiveWorkbook.Names.Add Name:="DATABASE2060", RefersToR1C1:= _
"='2060_DB'!R1C1:R8C9"

Now, I am trying to achieve the same result using VBA.

My code

Set LastCell = ActiveSheet.Range("I65536").End(xlUp)
SV_Code = 2060
Reference = "='" & SV_Code & "_DB!R1C1:" & LastCell.Address(ReferenceStyle:=xlR1C1)

ActiveWorkbook.Names.Add Name:="DATABASE2060", RefersToR1C1:= _
Reference

Running the vba code doesn't achieve the same result. Help guys

Try this, I think it will do the trick.

Range("A1", Range("I65536").End(xlUp).Address).Name = "DATABASE2060"

Regards,
 
Upvote 0
Whoops, make that

Sheets("2060_DB").Range("A1", Sheets("2060_DB").Range("I65536").End(xlUp).Address).Name = "DATABASE2060"

:smile:
 
Upvote 0

Forum statistics

Threads
1,223,516
Messages
6,172,778
Members
452,477
Latest member
DigDug2024

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