ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Codes for Undoing (https://www.excelbanter.com/excel-programming/421378-codes-undoing.html)

Varne

Codes for Undoing
 
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.

Mike Fogleman[_2_]

Codes for Undoing
 
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

"Varne" wrote in message
...
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.




Varne

Codes for Undoing
 
Thanks.

Could you please show me any method to do it - if any -?

M Varnendra

"Mike Fogleman" wrote:

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

"Varne" wrote in message
...
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.





Don Guillett

Codes for Undoing
 
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


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Varne" wrote in message
...
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.



xlm

Codes for Undoing
 
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,









"Varne" wrote:

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.



All times are GMT +1. The time now is 11:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com