Clear cells running a macro, and Undo

  • HI. I am trying to clear the below cells. When I hit my macro button, I am receiving an error. Also, after hitting my macro, how can I hit undo to bring contents back in case of an error?

    Code
    Sub Computation1()
    Sheets("computation").Range ("I7:Y27") * Range("J54:N200") * Range("j44:m50").ClearContents
    End Sub
  • Re: Clear cells running a macro, and Undo


    Code
    Sub Maybe()
    Sheets("computation").Range("I7:Y27, J54:N200, J44:M50").ClearContents
    End Sub


    When you delete with a macro it's gone to never come back again. There is no such thing as undo.
    If it is really required you might need to copy the sheet/workbook temporarely before running the code.

  • Re: Clear cells running a macro, and Undo


    Try this out :)


    [SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

  • Re: Clear cells running a macro, and Undo


    asternga,


    Please read the forum rules and learn to use code tags.


    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.
    Edit your thread to add the missing tags


    [COLOR="navy"]How to use code tags[/COLOR]


    [noparse]

    Code
    [/noparse]
    [COLOR="navy"]your code goes between these tags[/COLOR]
    [noparse]

    [/noparse]


    Or, just highlight all of the code and press the [COLOR="#FF0000"]#[/COLOR] button to add the code tags

  • Re: Clear cells running a macro, and Undo


    I was under the impression that the OP wanted to undo a macro command which is irreversible.
    I don't want the OP to have the idea that he can undo a macro command.
    From the MS site:
    Application.Undo undoes only the last action taken by the user before running the macro.
    It cannot be used to undo Visual Basic commands.

  • Re: Clear cells running a macro, and Undo


    I like this, however how can I make it where it clears the contents, and then ask proceed with changes? So, that if it accidently clears an incorrect cell, I can click no and it undo's what I cleared.

  • Re: Clear cells running a macro, and Undo


    Thread closed until OP acknowledges forum rules and agrees to use code tags.
    Send a PM per the above and I will unlock the thread.



    EDIT:
    PM received, thread re-opened

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!