+ Reply to Thread
Results 1 to 13 of 13

Macro to delete data on separate sheets

  1. #1
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Macro to delete data on separate sheets

    Ok, so the main sheet for my workbook has 2 userforms and a data view section. The data view section allows to input a serial number and it then pulls all records associated to that serial number from both sheets in which my userforms drop their data.

    The name of my main sheet where the data is being viewed (via vlookup formulas) is called "Main", the hidden data sheets that the userforms are sending the info to are called "ProductData" and "OrderData". The view data section on my main sheet locates all the product info on one sheet and locates all orders associated with that product and places them in a nice print-friendly format. I would like a button right on that sheet to DELETE all information attached to that serial number on my other sheets, preferably with a confirmation pop-up to prevent accidental deleting.

    The reason for this function would be to allow a user the chance to correct their error. Assuming the user accidentally input incorrect information in the userform, I need a way that they can easily remove that record. Sometimes this may occur at a later date when viewing a record in my data view section they see a mistake and want to remove that entire record and re-enter it correctly using the userforms once again.

    Hope it's clear.

    Ideas?
    Last edited by nohero; 06-15-2011 at 02:14 PM.

  2. #2
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Macro to delete data on separate sheets

    Anyone out there have any idea?

  3. #3
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Macro to delete data on separate sheets

    nohero,

    Perhaps if you provide a copy of the workbook this may help.
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  4. #4
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Macro to delete data on separate sheets

    So much proprietary info already in my workbook and also a ton of fluff that wouldn't be relevant to my issue so I just made this primitive version of my workbook to explain the issue.

    Example.xlsx

    Oops! Don't mind the "Quantity" section's lack of proper formatting, not important anyway.
    Last edited by nohero; 06-14-2011 at 04:40 PM.

  5. #5
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Macro to delete data on separate sheets

    nohero,

    Based on your example this is what I came up with.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Macro to delete data on separate sheets

    You seem to be on the right track but it's not quite working as intended. When I input 01234 and hit the Delete button it gave me the confirmation message but when I hit 'yes' it didn't actually delete the lines, when I hit 'no' it deleted every other serial from both sheets except the 01234.

    I re-added the 44444 serial as it was before and using your button (and pressing yes) it then removed it from the ProductInfo tab but not the Orders tab.

    Not sure how it needs to be tweaked, your coding is over my head.

    One thing I very much like about your coding is that it not only deletes the info in the row but removes the row entirely.

  7. #7
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Macro to delete data on separate sheets

    OK,


    I'll take a look

  8. #8
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Macro to delete data on separate sheets

    nohero,


    I looked at and modified the code. I hope this works for you. I added a Msgbox that pops up if the serial nr is not valid.


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Charles; 06-15-2011 at 12:41 PM. Reason: Posted code

  9. #9
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Macro to delete data on separate sheets

    This version is closer but still not quite there.

    When I put in a valid serial and choose 'yes' it will delete that serial from both other sheets and as far as I can tell works perfect.

    When I put in a valid serial but choose 'no' it will delete all other serials in both sheets except for the one I punched in.

    When I put in an invalid serial number whether I choose 'yes' or 'no' it will delete all serials from both pages.

    Lastly, when I choose 'no' (whether valid serial or not) the workbook brings up the 'Orders' worksheet. I would rather it remain on the 'Main' sheet.

    I really appreciate the time you've put into this and you're much closer than I ever would have been myself, I wish I knew how to tweak this a little bit more.

  10. #10
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Macro to delete data on separate sheets

    nohero,

    OK, I think I have it will modify code.

  11. #11
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Macro to delete data on separate sheets

    nohero,


    Ok I modified the code. Let's hope this one works. I tried the same procedure that you described and it appeared too work.


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

  12. #12
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Macro to delete data on separate sheets

    Tried every variation I can think of and it works like a charm!

    You are a lifesaver Charles, of all the great people that have have helped me on this site I am very glad you were the one to tackle this issue. It takes enough time to put something like this together and to do it with no reward... thank you.

    I wish there was a way to boost your rep 100 times.

    Thanks again.

  13. #13
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Macro to delete data on separate sheets

    nohero,

    Thanks for the complement and letting us know it all works well with you.

+ 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