Deleting names in activesheet only

David Bussell

New Member
Joined
Jun 2, 2009
Messages
22
I been looking for a way to limit the macro to just remove names within a single sheet and have just tried out the solution from lionpants. But it doesn't seem to work for me. By using workbooks, all names are deleted. When I use activesheet the macro runs, but no names are deleted.
any ideas?

Sub ByeByeNamedRanges()
Dim nm As Name
On Error Resume Next
For Each nm In ActiveSheet.Names
nm.Delete
Next
On Error GoTo 0
End Sub
<!-- / message -->
 
Hi, Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG22Nov46
[COLOR="Navy"]Dim[/COLOR] myName [COLOR="Navy"]As[/COLOR] Name, Ans [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer,[/COLOR] Msg [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
      [COLOR="Navy"]On[/COLOR] [COLOR="Navy"]Error[/COLOR] [COLOR="Navy"]Resume[/COLOR] [COLOR="Navy"]Next[/COLOR]
   [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] myName [COLOR="Navy"]In[/COLOR] ActiveWorkbook.Names
      [COLOR="Navy"]If[/COLOR] myName.RefersToRange.Worksheet.Name = ActiveSheet.Name [COLOR="Navy"]Then[/COLOR]
         Msg = myName.Name & " = " & myName.RefersToRange.Address
         Ans = MsgBox("Do you want to delete:- " & Msg, vbYesNo + vbInformation)
         [COLOR="Navy"]If[/COLOR] Ans = vbYes [COLOR="Navy"]Then[/COLOR] myName.Delete
      [COLOR="Navy"]End[/COLOR] If
   [COLOR="Navy"]Next[/COLOR] myName
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

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