Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

Delete Multiple Named Ranges Quickly


Bookmark and Share

This macro will allow you to delete multiple named ranges very quickly. When you run this macro, a message box will pop-up and ask you if you want to delete a named range; you then hit "Yes" or "Cancel" and then a message box will pop-up for the next named range with the same options as before. This will occur for every named range in the workbook. This way, you can see what the named range is and then quickly delete a large number of them if you need to. If you hit "Yes" on the message box, the named range will be deleted and if you hit "Cancel" the named range will not be deleted.
Where to install the macro:  Module

Delete Multiple Named Ranges Quickly

Sub Delete_Multiple_Named_Ranges_Quickly()

Dim nName As Name

Dim lReply As Long

    For Each nName In Names

        lReply = MsgBox("Delete the named range " & nName.Name _
            & vbNewLine & "It refers to: " & nName.RefersTo, _
            vbQuestion + vbYesNoCancel)

        If lReply = vbCancel Then Exit Sub

        If lReply = vbYes Then nName.Delete

    Next nName

End Sub


Bookmark and Share


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.



Similar Helpful Excel Resources

Delete Named Ranges And Reset Excel's Memory Of Previous Ranges - Excel

View Content
I'm trying to build a workbook that builds a query table based on a user's entry of a parameter and have this change when they enter a new parameter.

I've built the macro so that it's structured like so
1) clear any existing data
2) get data from report
3) copy and transpose it to another sheet
4) clear original site of the report

and attached this to a button called "Go".

That works fine, but Excel is remembering the fact that I've used the query table name before and incrementing it's name with a "_n" and is consequently causing me difficulties when I try referring to the named query table.

The code I'm using to delete existing named ranges is:
For Each nName In Names
nName.Delete
Next nName

Does anyone know how to do this and ensure that when excel creates the new named range it resets the count of the name to 0?

Thanks in advance

Delete Multiple Modules - Quickly - Excel

View Content
I have successfully rewritten all code in one workbook project. I have cut my Standard modules from 17 to just 4 modules.

Is there a way to remove all 17 modules at once so I can replace them with the 4 new ones?

I know that right clicking on the module and then click on "Remove...." will do it, but I would have to do that 17 times.

Not too bad if this was just one workbook to do. I have about 10 other books to do the same thing to. So that would be doing the right click 170 times.

I'm not even sure if this is possible. And if it is, I was thinking at probably having the code in a workbook open event to delete the Standard Modules??? Then I could just import the new modules.

Thanks
Harry

Delete Named Ranges In Specifc Ranges - Excel

View Content
Hi, I recently found a thread which describes how to delete all the named ranges in a workbook, I am trying to modify this slightly to only delete named ranges in the cell range or column specified:

Dim rName As Name
For Each rName In Range("A2:A10000")
rName.Delete
Next rName
End Sub

This produces an error, can anyone advise on this?

Delete Named Ranges - Excel

View Content
hi there... can i modify this code to select the named ranges i wantto delete from a list?

Sub DeleteRangeNames()
Dim rName As Name
For Each rName In ActiveWorkbook.Names
rName.Delete
Next rName
End Sub

cheers

Delete Named Ranges - Excel

View Content
Hi All,

I had a sub that have since misplaced...

It deleted all named ranges that started with the 3 letters that I typed into an input box....

Can anyone help me here .. I have thousands to delete...

keith

Vba To Delete Named Ranges - Excel

View Content
So I'm thinking this is an easy one. I ran this code that I found on this board to get a list of all the named ranges in my file:

Code:

Sub Find_bad_Names()
Dim i As Long
For i = 1 To ActiveWorkbook.Names.Count
    Sheets("Sheet2").Range("A" & i) = ActiveWorkbook.Names(i).Name
    Sheets("Sheet2").Range("B" & i) = "'" & ActiveWorkbook.Names(i).RefersTo
Next i

End Sub


That code worked great, I have about 4,000 named ranegs in this file, and the vast majority are ranges used in a different template that are irrelevant to this file. Luckily, all of these irrelevant named ranges names begin wth the text "IQ_".

So i tried the following code to delete named rnages that contain "IQ_" but it doesn't seem to be working. It seems to be looking at the "refersTo" value instead of the range name itself. Seems like a simple tweak but I'm not sure what to do.

Code:

Sub DeleteDeadNames()

Dim nName As Name

    For Each nName In Names

        If InStr(1, nName, "IQ_") > 0 Then

            nName.Delete

        End If

    Next nName

End Sub




Delete Named Ranges - Excel

View Content
Another one from my favourite spreadsheet...

I have a number of crazy defined names in my spreadsheet (1,746 to be exact). Not sure where they all came from, but I need them gone gone gone. Some of them start with squares at the front of the name and most of them refer to =#ref! or similar. I've seen a number of vba solutions to this, but none of them seem to work for me - I get "400" errors or run time errors. For reference, I'm hitting Alt F11, pasting the whole sub in, saving, then running....

Can anyone out there help?

Thanks again...

lmoon

Named Ranges - Can't Find Them To Delete Them - Excel

View Content
I have a worksheet that I update every morning and then copy the results to a workbook that has each day's worth of data on a different sheet. Whenever I copy the sheet to the other workbook, I keep getting messages that about 30 named ranges already exist and if I want to keep the new one or old one. I cannot find these ranges. They are not there. Where could they be hidden where I can find them to delete them, because I don't use them.

Thanks.

Delete Specific Named Ranges - Excel

View Content
I like to keep track of my named ranges on a separate sheet in my file (column A contains the name, column B its address reference). When I run the code that captures/lists them all, there are some that have been automatically added by Excel. For example:

Sheet1!_FilterDatabase
_xlfn.IFERROR

I have code to quickly delete any selection of names in a clump (shown below), but it doesn't work on these automatically created ones. Hoping someone has a suggestion for how to do that.

Thanks!

VB:

Sub DeleteRange() 
     
    Dim CL As Range 
    Dim rngName As String 
     
    For Each CL In Selection.Cells 
        rngName = CL.Value 
        On Error Resume Next 
        ActiveWorkbook.Names(rngName).Delete 
        On Error Goto 0 
    Next CL 
     
End Sub 


If you like these VB formatting tags please consider sponsoring me in support of injured Royal Marines



Delete Particular Named Range Or Ranges - Excel

View Content
how do you go about deleting particular named ranges? I have a macro that creates a sheet index at the front of the workbook (sourced from a MrExcel member years back). in doing so, it creates a named range on each sheet :
Code:

With wSheet
                .Range("A1").Name = "Start_" & wSheet.Index
                .Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
                                SubAddress:="Index", TextToDisplay:="Back to Sheet Index"


so in cell A1, on each sheet in the workbook, appears a hyperlink back to the Index sheet.

on the index sheet, it then anchors a hyperlink to that named range:
Code:

.Hyperlinks.Add Anchor:=WSIND.Cells(l, 1), Address:="", _
                                SubAddress:="Start_" & wSheet.Index, TextToDisplay:=wSheet.Name


so when you click on the sheet name on the sheet index, it takes you to cell A on that particular sheet.

another macro, fired as a close event, within the workbook reshuffles the tabs and then recreates the Sheet Index by calling the Sheet Index macro. The result is an ever increasing number of irrelevant named ranges beginning with "Start_".

unless there is a better method, I have been trying to delete the named range in cell A1 on each sheet using:
Code:

.Range("A1").Name.Delete


at the start of the With wSheet loop described above. while it doesn't bug out, it doesn't seem to do anything.

maybe there is a way to delete all named ranges beginning with "Start_"??????

love some suggestions please

Random Tutorials
Goal Seek Feature in Excel
(Intermediate)
FV() Find the Future Value of Cash Today
         -Savings/Retirement Plan Calculations

(Intermediate)
Bond Pricing Calculations for Simple Bonds
         - Future Value, Present Value, Interest Rate, etc.

(Intermediate)
Introduction to Making Formulas in Excel
(Easy)
HLOOKUP() Function - Introduction
(Intermediate)
Link Cells Between Worksheets
(Easy)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com