I have a simple bit of VBA code which I wrote, which just deletes three columns in a sheet when a button is pushed.
When the button is pushed, the columns are deleted. This part works fine. What I would like to do is make this action reversable via the STOCK undo button in Excel. Currently, the deletion of these rows is not able to be undone by any means (that I am aware of), which means that if the button is pushed on accident then the sheet has to be exited and re-opened.
Here is my current code, please feel free to critique it as well, I am not very familiar with VBA best practices, although I am learning.
Private Sub CommandButton1_Click()
Dim Alias_Adds As Worksheet
Set Alias_Adds = Sheets("Alias_Adds")
MSG1 = MsgBox("Are you ready to delete the validation columns? (A, F, and G?)", vbYesNo, "")
If MSG1 = vbYes Then
With Alias_Adds
Alias_Adds.Columns("A").EntireColumn.Delete 'this is the line that is cauing the error
Alias_Adds.Columns("E:F").EntireColumn.Delete
End With
Else
MsgBox "Ok, let's wait a bit to delete those columns"
End If
End Sub