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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,215,110
Messages
6,123,147
Members
449,098
Latest member
Doanvanhieu

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