Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undo an Excel macro

Status
Not open for further replies.

pe

Technical User
Aug 8, 2001
31
US
I have the following macro to delete blank rows in an Excel worksheet...

Public Sub DeleteBlankRows()

Dim R As Long
Dim C As Range
Dim N As Long
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
N = 0
For R = Rng.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountA(Rng.Rows(R).EntireRow) = 0 Then
Rng.Rows(R).EntireRow.Delete
N = N + 1
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

How can I add a procedure to undo the above macro and put the worksheet back with all the blank rows it just took out? Thanks for the help.
 
my only one idea (i don't know how to append macro actions, and orig values to the undo list):
copy your activeSheet to an invisible tempSheet into your workbook. If you want to undo macro, delete activeSheet and rename tempSheet to activeSheet.name. Create a close event macro with command to delete tempSheets. This restore the state of wsheet before creating tempSheet.
 
sounds like a good idea. i'll try it. thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top