Results 1 to 3 of 3

Delete nearly all defined names from the active worksheet only

Threaded View

  1. #1
    Registered User
    Join Date
    08-31-2012
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007
    Posts
    6

    Delete nearly all defined names from the active worksheet only

    Excel 2007

    Need to delete nearly all defined names from the active worksheet only. Worksheets can be named anything.

    These two worksheets must be excluded from having any names deleted:

    .codename(“Sheet1”)
    .name(“Summary”)

    Also, I don’t want any ~system names deleted, so exclude:
    (although Print_Area is the only one I’ve seen…)

    *_FilterDatabase
    *Print_Area
    *Print_Titles
    *wvu.*
    *wrn.*
    *!Criteria

    I have been trying to get something like this working (from searching these and other forums):

    Sub deleteinvalidnames()
    
    Dim invalidname As name
    Dim Ans As Integer
    Dim Msg As String
     
    For Each invalidname In ActiveWorkbook.Names
         If invalidname.RefersToRange.Worksheet.name = ActiveSheet And _
             Not invalidname.name Like "*Print_Area" And _
             ActiveSheet.CodeName <> "Sheet1" And _
             ActiveSheet.name <> "Summary" Then
                  Msg = invalidname.name & " = " & invalidname.RefersToRange.Address
                  Ans = MsgBox("Do you want to Delete/Rename: " & Msg, vbYesNo + vbInformation)
                  If Ans = vbYes Then invalidname.Delete
         End If
      Next invalidname
     
    ‘Then run other macro to create new names (this has no issues)…
    resetnames
     
    End Sub
    I’ve tried some mixes with:

    Set ws = Activesheet
    With ws
       For each invalidname in ws.names
    etc. but nothing seems to work.

    I don’t really need to cycle through with each name, but I came across that code first and it looked like a good thing to have in while troubleshooting…

    http://www.mrexcel.com/forum/excel-q...heet-only.html

    I would appreciate any advice as to how to proceed. Thank you.
    Last edited by JBeaucaire; 09-15-2013 at 08:16 PM. Reason: Added CODE tags, as per Forum Rules. Take a moment to read the Forum Rules in the menu bar above. Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 04-04-2010, 04:15 AM
  2. [SOLVED] delete defined names
    By Todd in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2006, 04:15 PM
  3. How to delete all defined names from a workbook?
    By Dmitry Kopnichev in forum Excel General
    Replies: 15
    Last Post: 11-14-2005, 11:30 AM
  4. How to delete all defined names from a workbook?
    By Dmitry Kopnichev in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 11-14-2005, 11:30 AM
  5. Macro to delete Defined Names
    By Mike Piazza in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2005, 02:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1