How to delete a single named range from a worksheet

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
572
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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,215,101
Messages
6,123,092
Members
449,095
Latest member
gwguy

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