+ Reply to Thread
Results 1 to 6 of 6

How to delete all define names in Excel

Hybrid View

  1. #1
    Registered User
    Join Date
    01-18-2005
    Posts
    62

    How to delete all define names in Excel

    Dear all,

    In order to delete all define name in Excel I create a below macro:

    Sub NamTest()
    
    
    For i = 1 To ActiveWorkbook.Names.Count
    
     MyName = ActiveWorkbook.Names.Item(i).Name
     ActiveWorkbook.Names(MyName).Delete
    
    Next
    End Sub
    However, there is an error message 'This name is not valid'.

    Could anyone can help me.

    Thanks

    Nam
    Last edited by mudraker; 06-26-2007 at 12:25 AM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    You have to work in descending order when deleting names.

    For i = ActiveWorkbook.Names.Count to 1 step -1
      ActiveWorkbook.Names(MyName).Delete
    Next i

    rylo

  3. #3
    Registered User
    Join Date
    01-18-2005
    Posts
    62
    Hi rylo,

    Thanks.

    I try to do your code but the same problem still happens.

    Could any one can help me.

    Thanks,

    Nam

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Silly me forgot to modify the code fully....

    Try

    For i = Application.Names.Count To 1 Step -1
        Application.Names(i).Delete
      Next i

    rylo

  5. #5
    Registered User
    Join Date
    01-18-2005
    Posts
    62
    Dear roly,

    Thanks for your help.

    I tried to apply your VBA code but I still have the same problem.

    Regards,

    Nam

  6. #6
    Forum Contributor
    Join Date
    11-17-2006
    Posts
    152
    This is the code put together as roly suggested.

    Sub NamTest()
    
    For i = Application.Names.Count To 1 Step -1
    MsgBox (i)
        Application.Names(i).Delete
      Next i
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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