+ Reply to Thread
Results 1 to 18 of 18

Macro which deletes rows stops at empty row

  1. #1
    Registered User
    Join Date
    04-19-2010
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    86

    Macro which deletes rows stops at empty row

    Hi Guys

    I'm pretty clueless when it comes to this, so please bear with me. Basically i have a simple macro which adds/deletes rows of locations in an excel worksheet, one click of the add button adds a row, and one click of the delete button deletes a row. If there is more than one location for a customer, the user clicks add and it inserts a row, and of course vice versa.

    I have the row to be copied stored in another worksheet (which I will hide) so that even if all the rows are deleted, I still have the source row, but the problem is that when all the location rows are deleted it starts deleting all the other rows below. The next row after the locations is blank, so is there anything I can insert into the code to stop the macro deleting a row if it is blank?

    Thanks
    John

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: Macro which deletes rows stops at empty row

    Please post a sample workbook.

    Regards

  3. #3
    Registered User
    Join Date
    04-19-2010
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro which deletes rows stops at empty row

    Hi there, I've attached the example workbook. As you can see it's very basic. All I want to do is when the user clicks on "Delete Location", when all the locations are deleted I want the macro to stop i.e. when there is a blank row in row 64.

    Any help would be greatly appreciated!

    John
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    04-19-2010
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro which deletes rows stops at empty row

    Is the file okay?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: Macro which deletes rows stops at empty row

    Yes, it's fine ... just been busy.

    Try this:

    Please Login or Register  to view this content.


    Regards

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: Macro which deletes rows stops at empty row

    Improved Insert Location module:

    Please Login or Register  to view this content.

    Regards

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: Macro which deletes rows stops at empty row

    Is the solution okay? ;-)

  8. #8
    Registered User
    Join Date
    04-19-2010
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro which deletes rows stops at empty row

    Oh my! Worked like a charm! Thank you SO much, my boss is going to love me now
    John

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: Macro which deletes rows stops at empty row

    You're very welcome. Thanks for the feedback.

    You don't necessarily need the message box, if you don't want it. Just comment it out. Then pressing the button will just appear to have no effect ... but it won't require positive action to dismiss the message.

    Regards

  10. #10
    Registered User
    Join Date
    04-19-2010
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro which deletes rows stops at empty row

    Hi again!

    I have another problem:

    My boss told me they needed another section with the ability to insert and delete rows. So now I have two sections that do this.

    It's not a problem for the first section, but if I add or delete rows in the first section it messes up my macros for the second section!

    Any ideas? I've attached my file again...this might be an awkward one
    Attached Files Attached Files

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: Macro which deletes rows stops at empty row

    OK. I understand.

    I have it sussed but it may be tomorrow before I can spend time on the fine detail and testing.

    It's not that difficult so it shouldn't take too long once I can focus on it.

    Just so you know where we're at.

    Regards

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: Macro which deletes rows stops at empty row

    Try this.

    All subroutines combined into one module. Other modules removed.

    Original code (my code, that is) modified to work relative to identifiable section headers, rather than fixed rows and ranges.

    New code replicated for subcontractor addition and deletion.

    Seems resilient enough ... but not tested to destruction :-)

    If your boss wants any more sections adding and deleting, you should be able to work it out from this. Have fun.

    Take care
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    04-19-2010
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro which deletes rows stops at empty row

    HOLY MACKEREL!!! You really are amazing! Thanks SO much. I'm going to test it thoroughly today, although it seems to work brilliantly from what I've seen...absolute genius.

    I'm going to really work hard to completely understand what you've done there as well, it's really clever...

    Again, thanks so much!!!!

  14. #14
    Registered User
    Join Date
    04-19-2010
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro which deletes rows stops at empty row

    Hey - just to be extra annoying, there's one more thing which I can't figure out - is it possible to add a checkbox (as shown in the attached file) so that it copies to each row when a location is added?
    The purpose is to have a checkbox next to each additional site location for the user to tick if it needs to be visited. If not I guess it would be simpler just to mark an 'x' in a cell?

    Thanks
    John
    Attached Files Attached Files

  15. #15
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: Macro which deletes rows stops at empty row

    "one more thing" ... just, "one more thing"? Hahh.

    Give me a while; I'll get back to you.

    Regards

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: Macro which deletes rows stops at empty row

    OK, see the attached updated workbook.

    Let me know how you get on.

    If you're getting a bonus for this, just send me a cheque :-)

    Regards
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    04-19-2010
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro which deletes rows stops at empty row

    Haha - brilliant... thanks again!

  18. #18
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: Macro which deletes rows stops at empty row

    What can I say? Thanks for the feedback.

+ 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