+ Reply to Thread
Results 1 to 10 of 10

How to ask for a confirmation before a range/a cell content(s) is/are deleted?

  1. #1
    Registered User
    Join Date
    04-25-2012
    Location
    Curacao
    MS-Off Ver
    Excel 2003
    Posts
    18

    How to ask for a confirmation before a range/a cell content(s) is/are deleted?

    Dear Excel Friends,

    I have the following vba code:

    Please Login or Register  to view this content.
    If I want to delete the cell contents of cells in a range, this code asks me if i want to delete the contents of a cell. First with a message box with yes or no and a confirmation is asked by entering a word.
    However this code only works when 1 cell is selected. In case more cells in the range are selected, it does not work. Can somebody help me?

    with kind regards,

    Marc
    Last edited by zbor; 07-06-2012 at 08:02 AM.

  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
    44,447

    Re: How to ask for a confirmation before a range/a cell content(s) is/are deleted?

    You'd need to take out the Target.Count test and then loop through each cell in Target.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    04-25-2012
    Location
    Curacao
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: How to ask for a confirmation before a range/a cell content(s) is/are deleted?

    Hey TMShucks,


    Please Login or Register  to view this content.
    Is it something like this? Or what do I forget after the loop?

    Thanks thanks a lot.

    gr marc
    Last edited by zbor; 07-06-2012 at 08:02 AM.

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: How to ask for a confirmation before a range/a cell content(s) is/are deleted?

    As TMShucks told you:

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing.

    Edit your post, highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  5. #5
    Registered User
    Join Date
    04-25-2012
    Location
    Curacao
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: How to ask for a confirmation before a range/a cell content(s) is/are deleted?

    Hey TMShucks,



    Please Login or Register  to view this content.
    Is it something like this? Or what do I forget after the loop?

    Thanks thanks a lot.

    gr marc

  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
    44,447

    Re: How to ask for a confirmation before a range/a cell content(s) is/are deleted?

    Please Login or Register  to view this content.


    Regards, TMS
    Last edited by TMS; 07-05-2012 at 10:59 AM.

  7. #7
    Registered User
    Join Date
    04-25-2012
    Location
    Curacao
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: How to ask for a confirmation before a range/a cell content(s) is/are deleted?

    Dear TMS,

    now it works indeed. But not exactly how i want it to work.
    In case i select a single cell in the range and delete it, after a confirmation I can delete it. However if I select a bigger range (more cells), it asks if I would like to delete it and after confirmation it only deletes the contents of one cell. What is missing in the code?

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    with kind regards,

    Marc Pustjens
    Last edited by TravelDrome; 07-06-2012 at 07:58 AM.

  8. #8
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How to ask for a confirmation before a range/a cell content(s) is/are deleted?

    TravelDrome

    Please add code tags to your original post and post #3 as requested by zbor in post #4.

  9. #9
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: How to ask for a confirmation before a range/a cell content(s) is/are deleted?

    TravelDrome, we ask you few times to put tags around your code in post 1.
    I did it now for you but next time I'll have to give you infraction.

  10. #10
    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
    44,447

    Re: How to ask for a confirmation before a range/a cell content(s) is/are deleted?

    Please make sure you comply with the moderator's requests in future as, in accordance with the forum rules, no one can answer your question without incurring an infraction themselves.

    I'm guessing the first time you run the routine it will undo ALL the changes. I think you need to issue the Undo before you start the loop and store the current and previous values. Then you can do a comparison in the loop and clear the value or not.

    Regards, TMS

+ 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