How to delete a single named range from a worksheet

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
585
Office Version
  1. 365
Platform
  1. Windows
Hi,

This seems like a silly question, but nothing I've tried seems to work. I have a worksheet called "Jobs" and on that worksheet there is a named range called "HYDROJNRange". I've placed the line of code below in my macro to get rid of it, but I keep getting a Runtime Error 1004 "Application-defined or Object-defined error". Any help on what I am missing here would be greatly appreciated.


Thanks, SS



VBA Code:
    ActiveWorkbook.Names("HYDROJNRange").Delete
 
Ok, I think I found the trick to creating it with the Workbook Scope. Changed the last bit of code that created the named range to the following and it worked.

VBA Code:
Sub HYDROJNRange()

    Dim iName As String
    iName = "HYDROJNRange"
'    ActiveSheet.Names.Add Name:=iName, RefersTo:=Selection
    ActiveWorkbook.Names.Add Name:=iName, RefersTo:=Selection
    
End Sub

Thanks for all the help and clearing this up for me.
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,224,603
Messages
6,179,854
Members
452,948
Latest member
UsmanAli786

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