+ Reply to Thread
Results 1 to 5 of 5

VBA Macro Does not Delete Most Recent Defined Named Range

  1. #1
    Registered User
    Join Date
    02-11-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    11

    VBA Macro Does not Delete Most Recent Defined Named Range

    As you can see from the macro below (also located in Sheet1 of the attached spreadsheet), I am trying to create and then delete specific named ranges. I will add more code between the creation and deletion sections after I get this part of the code to work. Unfortunately, the macro is not deleting the most recently defined named range. If Group5 is the last named range, the macro will only delete the Group5 named range every other time I run the macro. If I create Group5 on the first run of the macro, the macro does not delete Group5. The second time I run the macro, the macro does delete Group5. The third time I run the macro, Group5 is not deleted. The fourth time it is deleted, etc. Does anyone have suggestions regarding what code I am missing to make my macro run correctly?


    Please Login or Register  to view this content.
    Attached Files Attached Files

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

    Re: VBA Macro Does not Delete Most Recent Defined Named Range

    Hi

    Why don't you just go down the track of deleting all the names and then fill them as required?

    Please Login or Register  to view this content.
    rylo

  3. #3
    Registered User
    Join Date
    02-11-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: VBA Macro Does not Delete Most Recent Defined Named Range

    Terrific! Vast improvement on my code. Thank you. Although the code works on the example spreadsheet I attached, I am getting a "Type mismatch" error on line "If Cells(3, i) Then" when I try to use the code on my real spreadsheet. I thought I had made my example as close to my real worksheet as possible, but I see now that the columns that are populated on each spreadsheet are different. My apologies for this oversight, but would you mind modifying the code for the attached spreadsheet (the REAL location of each cell on my real spreadsheet)? I tried to modify the code on my own but was unsuccessful. Also, what does "If Cells(3, i) Then" mean? I thought that an If/Then statement had to look to see if something equaled, was more than, or was less than something else; but your line has no "=" or "<" or ">". Thank you very much for your improved code over the lengthy one that I created!
    Attached Files Attached Files

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

    Re: VBA Macro Does not Delete Most Recent Defined Named Range

    HI

    OK, here goes
    Please Login or Register  to view this content.
    The if statement does a test to determine if something gives a TRUE/FALSE result. So a test of 2=2 will give TRUE, but 2=3 will give false. As the result in row 11 from the tick box gives a TRUE/FALSE result, you can just test that directly.

    Does that make sense?

    rylo

  5. #5
    Registered User
    Join Date
    02-11-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: VBA Macro Does not Delete Most Recent Defined Named Range

    rylo,

    Yes, it does make sense. I appreciate the explanation, because it will help me in writing better code. Thank you also for modifying the code for me. It works like a charm and helped me cut down on countless employee manhours.

    Thank you taking the time to help me!

+ 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