+ Reply to Thread
Results 1 to 15 of 15

Deleting Specified Named Ranges

  1. #1
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Deleting Specified Named Ranges

    I have around 50 named ranges in a Workbook and I need to delete a number of them. I've tried a couple of approaches but I'm getting an error with each one.

    The Error I'm getting is '1004' - Application-defined or object-defined error

    Please Login or Register  to view this content.
    Anyone know why I'm getting the error?

    I also tried this but ran into an error!

    Please Login or Register  to view this content.
    Many thanks

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Deleting Specified Named Ranges

    Have you tried :- Range(nr).Delete

  3. #3
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Deleting Specified Named Ranges

    I haven't, but will. I'm curious to know why the two existing approaches give me an error though?

    Will report back later...

  4. #4
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Deleting Specified Named Ranges

    this walks tru all names and ask to delete

    Please Login or Register  to view this content.
    Kind regards
    Leo

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Deleting Specified Named Ranges

    Anyone know why I'm getting the error?
    The code is trying to delete a named range that doesn't exist. Make sure the names in your array are all valid named range or turn off error messages.

    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  6. #6
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Deleting Specified Named Ranges

    Hi Trebor76,

    I'm not sure I follow. I started by printing out a list of all the named ranges in the workbook using this piece of code

    Please Login or Register  to view this content.
    I then copied and pasted the names in to various possible solutions but I get an error every single time.

    If I simply type:

    Please Login or Register  to view this content.
    It works fine which shows the name exists, but I really don't want to have to type that line 50 times hence trying to find a better solution.

    This is what I've tried so far, all solutions from different websites, but each one gives me an error:

    Please Login or Register  to view this content.
    - This gives me a '1004' - Application-defined or object-defined error

    Please Login or Register  to view this content.
    Solution 2 - This gives me a '1004' - Method 'range' of 'object_global' failed error

    Please Login or Register  to view this content.
    Solution 3 - This gives be a '1004' - The name you entered is not valid, reasons can incude... error

    Please Login or Register  to view this content.
    My code is sitting within:

    Please Login or Register  to view this content.
    but still no joy, so I'm completely bafled.

  7. #7
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Deleting Specified Named Ranges

    Hi Leo,

    Your code works, but it also gives a '1004' Application-defined or 'object-defined' error at the end. Isn't sandwiching the code between

    Please Login or Register  to view this content.
    just disguising the error?

    What I need though is a solution where I can define which named ranges to keep or alternatively which to delete without the user saying 'Yes' or 'No' to each. This needs to happen effectively in the background without the user being aware there are named ranges being deleted at all.

    One thing that baffled me was that it also listed three 'named ranges' which I haven't created and are not visible in the 'Names' dialogue, namely:

    xlfm.COUNTIFS
    xlfm.ERROR
    xlfm.SUMIFS

    Are these built in defaults or something? Would there be implcations if they were deleted as well?

    Many thanks
    Last edited by HangMan; 09-13-2015 at 11:05 AM.

  8. #8
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Deleting Specified Named Ranges

    Hi MickG,

    I tried Range(nr).Delete but I still get the same error I'm afraid.

    Many thanks

  9. #9
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Deleting Specified Named Ranges

    are one, two, three ....... the real names ?

  10. #10
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Deleting Specified Named Ranges

    Hi Leo,

    No, but the real names take the format Name, Name_Something, Name_Something_Else. The sheet is sensitive which is why I didn't put the real names.

  11. #11
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Deleting Specified Named Ranges

    Hi Hangman,

    in item you put all the names like exemple below

    Please Login or Register  to view this content.

    Kind regards
    Leo

  12. #12
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Deleting Specified Named Ranges

    Hi Leo,

    A couple of things, firstly the code runs and deletes 'most' of the named ranges, but I still get the '1004' - Application-defined or 'object-defined' error after the code has run which is a problem because I can't have the user seeing this error.

    I have a list of around 50 or so named ranges I want to delete, how can I enter these with line breaks in the code?

    If I do the usual "One, Two, Three, Four _
    Five, Six, Seven"

    etc., it won't accept it, the text is then highlighted in red

    There are a couple of named ranges which relate to pivot table slicers, they have no value and refer to nothing, so it probably doesn't matter if they don't get deleted, but for whatever reason, even though they are listed, they don't automatically get deleted using the code.

    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Deleting Specified Named Ranges

    Hi Hangman,

    i dont have experience with tables or pivot tables but i think
    you cant remove those names.

    so the, on error resume next will handle the job for the other names

    Please Login or Register  to view this content.
    Kind regards
    Leo

  14. #14
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Deleting Specified Named Ranges

    and just see you use the , after the name dont do only the name a space and next name


    Kind regards
    Leo

  15. #15
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Deleting Specified Named Ranges

    Leo,

    That seems to have done the trick, simple when you know how...

    Many thanks for your help, it is very much appreciated...

+ 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. Deleting Named Ranges takes too long
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-24-2015, 09:12 AM
  2. Deleting named ranges that do not have comments
    By Ezzard in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-27-2015, 01:15 PM
  3. [SOLVED] Deleting Hidden named ranges with vba code
    By GavinMcL in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-11-2014, 09:07 AM
  4. Replies: 13
    Last Post: 07-15-2013, 08:14 PM
  5. deleting named ranges
    By Hein in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-28-2009, 09:27 AM
  6. [SOLVED] Deleting Named Ranges
    By Grant Reid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-27-2005, 11:05 AM
  7. Deleting many named ranges
    By Tom Hayakawa in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-28-2005, 06: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