Hello, I have a question pertaining to 'undoing' a macro command that I have coded. I created a workbook with two sheets (assignments; completed assignments) that has a list of assignments on the 'assignments' sheet. I added a conditional progress bar at the end of each assignment row on the 'assignments' sheet that determines how complete a particular assignment is for any given row that contains multiple criteria. Once the progress bar reaches 100%, the entire row makes a strike-through and fades out (this is another conditional format change I made; not essential information for my question). I then created and assigned my 'HelloWorld' macro to a button that, when pressed, will scan the 'assignments' sheet for any row(s) that contain 100%. If they do, it will automatically copy, delete, and move the next row up; and then finally paste the 100% complete row into the 'completed assignments' sheet. The only issue is that if the button is accidentally pressed by a user before intended, this command cannot be undone because Excel does not natively store changes made by macros. This can be solved by 'closing without saving' but I thought it would be nice to be able to code a macro that will undo what was previously done. Based off the research I've done so far, I think I can use 'Application.Undo' in some way but am not sure how to integrate it, since I am new to VBA. Any help would be greatly appreciated! I am using Excel 2013 on Windows 10. Below is the macro code that works well and is described above. Also, because I am new to this forum, if there is anything I missed or can do next time differently when posting a question or answer to improve others' experiences, please let me know. Thank you.
Sub HelloWorld() Dim xRg As Range Dim xCell As Range Dim I As Long Dim Z As Long Dim K As Long I = Worksheets("Assignments").UsedRange.Rows.Count Z = Worksheets("Completed Assignments").UsedRange.Rows.Count If Z = 1 Then If Application.WorksheetFunction.CountA(Worksheets("Completed Assignments").UsedRange) = 0 Then Z = 0 End If Set xRg = Worksheets("Assignments").Range("T1:T" & I) 'T is the column that contains the progress bar On Error Resume Next Application.ScreenUpdating = False For K = 1 To xRg.Count If CStr(xRg(K).Value) = "1" Then xRg(K).EntireRow.Copy Destination:=Worksheets("Completed Assignments").Range("A" & Z + 1) 'Copies row to other sheet xRg(K).EntireRow.Delete 'Deletes previous row If CStr(xRg(K).Value) = "1" Then K = K - 1 End If Z = Z + 1 End If Next Application.ScreenUpdating = True End Sub