K
ktoth04
The following code updates a 'date edited' column in a worksheet we use.
However, it also seems to disable the undo command. I understand not being
able to edit the changes vba makes, but you cant undo an edit you make. this
is probably because vba is making a change after everything you edit. Is
there any way to re-enable Undo?
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo errHandler
If Target.Count > 1 Then
Exit Sub
Else
If Right(Target.Address, 2) = "$1" Then Exit Sub
End If
With Application
..EnableEvents = False
..ScreenUpdating = False
End With
With Me
If Left(Target.Address, 3) = "$A$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$B$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$C$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$E$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$F$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$G$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$H$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$I$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$J$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$K$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$L$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$M$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$N$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$O$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$P$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$Q$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$R$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$S$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$T$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$U$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$V$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$W$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$X$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$Y$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$Z$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AA$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AB$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AC$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AD$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AE$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AF$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AG$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AH$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AI$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AJ$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AK$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AL$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AM$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AN$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AO$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AP$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AQ$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AR$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AS$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AT$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AU$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AV$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AW$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AX$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AY$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AZ$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
End If
End With
With Application
..EnableEvents = True
..ScreenUpdating = True
End With
Exit Sub
errHandler:
MsgBox Err.Number & " " & Err.Description
Application.EnableEvents = True
End Sub
However, it also seems to disable the undo command. I understand not being
able to edit the changes vba makes, but you cant undo an edit you make. this
is probably because vba is making a change after everything you edit. Is
there any way to re-enable Undo?
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo errHandler
If Target.Count > 1 Then
Exit Sub
Else
If Right(Target.Address, 2) = "$1" Then Exit Sub
End If
With Application
..EnableEvents = False
..ScreenUpdating = False
End With
With Me
If Left(Target.Address, 3) = "$A$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$B$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$C$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$E$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$F$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$G$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$H$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$I$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$J$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$K$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$L$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$M$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$N$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$O$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$P$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$Q$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$R$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$S$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$T$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$U$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$V$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$W$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$X$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$Y$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$Z$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AA$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AB$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AC$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AD$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AE$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AF$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AG$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AH$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AI$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AJ$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AK$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AL$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AM$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AN$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AO$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AP$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AQ$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AR$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AS$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AT$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AU$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AV$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AW$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AX$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AY$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
ElseIf Left(Target.Address, 3) = "$AZ$" Then
With Range("D" & Target.Row)
..Formula = "=NOW()"
..Calculate
..Value = .Value
End With
End If
End With
With Application
..EnableEvents = True
..ScreenUpdating = True
End With
Exit Sub
errHandler:
MsgBox Err.Number & " " & Err.Description
Application.EnableEvents = True
End Sub