Hi all! I'm very new to Excel VBA, and needed to implement a functionality into my sheet that would
Can anyone please help identify what's wrong with the code below and how to fix it? I tried googling extensively but to no avail...
Thanks a ton!
- automatically insert a date into column W when any new value was added to column C
- automatically insert a date into column X when a value in column K is changed to "Payment Done", but only then and never in any other cases
Can anyone please help identify what's wrong with the code below and how to fix it? I tried googling extensively but to no avail...
Thanks a ton!
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140722
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("C:C"), Target)
xOffsetColumn = 20
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mmm-yy"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
If Target.Column = 11 And Target.Value = "Payment Done" And Target.Offset(0, 13).Value = "" Then
Target.Offset(0, 13) = Format(Now(), "dd-mmm-yy")
End If
End Sub