Codes for Undoing

  • Thread starter Thread starter Varne
  • Start date Start date
V

Varne

Hi

Could somebody give me codes for undoing? It is urgent.

Sub Test ()

Cells(1,1).ClearContents
Application.Undo

End Sub

The above does not work.

Thanks.
 
From Help for Undo...
This method undoes only the last action taken by the user before running the
macro, and it must be the first line in the macro. It cannot be used to undo
Visual Basic commands.

It can't Undo a VB command to ClearContents

You can assign the contents to a variable, ClearContents and then re-assign
the variable to the cell.



Mike F
 
You can't undo macros.

Public oldvalue
'put above as top line in module

Sub clearem()
oldvalue = Cells(1, 1)
Cells(1, 1).ClearContents
End Sub

Sub undoem()
Cells(1, 1) = oldvalue
End Sub
 
Hi Varne

However, you can have a macro to store the old value and have the changed
data restore back.

see this link http://j-walk.com/ss/excel/tips/tip23.htm

This can undo your subroutine only once. I would suggest that you save a
backup copy of your workbook / worksheets before running a macro.

HTH

--
If this posting was helpful, please click on the Yes button

Thank You

cheers,
 
Back
Top