none
VBScript RRS feed

  • Question

  • Sub Demo()
        If ActiveCell.Column = 11 Then
            ActiveCell.Value = Time
        End If
    End Sub

    After executing above macro how can i undo if i don't want above action to be implemented.

    Saturday, June 29, 2019 7:01 PM

All replies

  • Running a macro that changes cell values clears Excel's undo stack, so it isn't possible to undo the action of the macro.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, June 29, 2019 7:11 PM
  • JtP,
    Re: undoing

    You could write your own undo script.
    It can get complicated.  It might look like this...
    '---
    Public vRetainValue(1, 2) As Variant

    Sub Demo()
      If ActiveCell.Column = 11 Then
         vRetainValue(1, 1) = ActiveCell.Address
         vRetainValue(1, 2) = ActiveCell.Value
         ActiveCell.Value = Time
      End If
    End Sub

    Sub UnDoDemo()
    If Not IsEmpty(vRetainValue(1, 1)) Then
      Range(vRetainValue(1, 1)).Value = vRetainValue(1, 2)
      vRetainValue(1, 1) = Empty: vRetainValue(1, 2) = Empty
    End If
    End Sub
    '---

    Special_Randoms workbook
    Download from MediaFire

    Saturday, June 29, 2019 11:21 PM