Consulting

Results 1 to 5 of 5

Thread: Enabling "undo" on "time stamp vba code"

  1. #1
    VBAX Regular
    Joined
    Aug 2011
    Posts
    60
    Location

    Enabling "undo" on "time stamp vba code"

    Hi,
    I've search on some sites that "undo" is not enable when the following code is applied:

    [VBA]
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 Then
    Application.EnableEvents = False
    Target.Offset.Offset(0, 1) = Now()
    Application.EnableEvents = True
    End If
    End Sub
    [/VBA]

    It will be better if we can "undo" cause when I accidentally type over on the next cell, I have to not safe my work and redo the whole thing all over again.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    You would need to program some undo action, maybe have a button to undo the last action, which means saving previous states.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Aug 2011
    Posts
    60
    Location
    Quote Originally Posted by xld
    You would need to program some undo action, maybe have a button to undo the last action, which means saving previous states.
    Hi xld,
    Any clue on how to do it? Since "Ctrl + Z" doesn't work when that code is applied

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    Yes, as I said, when you change things you need to save their previous state, maybe a 2D array of cell address and value, and then have an undo button that re-applies from within that array. You would have to manage the array, set a limit and shunt things in and out.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    This code will save the value in column B to the Office Toolbar before overwriting it. You can then access the Office toolbar to paste the value back into the cell.

    [VBA]
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 Then
    Application.EnableEvents = False
    If Not IsEmpty(Target.Offset(0, 1)) Then
    Target.Offset(0, 1).Copy
    End If
    Target.Offset(0, 1) = Now()
    Application.EnableEvents = True
    End If
    End Sub
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •