+ Reply to Thread
Results 1 to 5 of 5

How to Delete Named Ranges in A specific Sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    07-19-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2013
    Posts
    36

    How to Delete Named Ranges in A specific Sheet

    Hey Everyone,

    I have named ranges in a particular worksheet. All the named ranges are specific only. Someone helped me concatenate the appropriate strings. Awesome.

    However, I want the user of the worksheet to be able to clear the names of the worksheet before they start naming the ranges. Just in case. I found something else and I'm trying to adapt it

    specifically this is where I am:

    Sub delnames()
    
        Dim nName As Name
    
        Dim shtname As String
        shtname = ActiveSheet.Name
    
    
    For Each nName In ThisWorkbook.Names
            If nName.RefersTo = "=" & shtname & "'!" Then nName.Delete
        Next
    
    
    End Sub
    I think I may need to use something other than RefersTo. Is there some string specific conditional I might want to use?

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: How to Delete Named Ranges in A specific Sheet

    Hi,

    Try this For Each...Next loop instead:
    For Each nName In ThisWorkbook.Names
        If nName.RefersToRange.Worksheet.Name = shtname Then
            nName.Delete
        End If
    Next nName
    Hope this helps

  3. #3
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: How to Delete Named Ranges in A specific Sheet

    Or another loop that would also work is:
    For Each nName In ThisWorkbook.Names
        If InStr(1, nName, shtname) Then
            nName.Delete
        End If
    Next nName

  4. #4
    Registered User
    Join Date
    07-19-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2013
    Posts
    36

    Re: How to Delete Named Ranges in A specific Sheet

    Hey Ajryan88,

    Both worked great! The InStr is what I was thinking about. I'll use that next time. For this sort of thing. Thanks again!

  5. #5
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: How to Delete Named Ranges in A specific Sheet

    No problems! Glad I could help

    Please don't forget to mark this thread as solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How do I delete all named ranges in a sheet at one time?
    By Dave Peterson in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-06-2005, 03:05 PM
  2. How do I delete all named ranges in a sheet at one time?
    By Dave Peterson in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 07:05 AM
  3. [SOLVED] How do I delete all named ranges in a sheet at one time?
    By L.Wall in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  4. How do I delete all named ranges in a sheet at one time?
    By L.Wall in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM
  5. Delete broken named ranges in sheet
    By akyhne in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-15-2005, 06:05 PM

Tags for this Thread

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