I have the following macro:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 1 Or Target.Column = 2 Then
MsgBox "You just changed " & Target.Address
MsgBox "You just changed Row " & Target.Row
MsgBox "I would like to change the date in Cell " & Target.Range("C" & Target.Row).Address
Target.Range("C" & Target.Row).Value = Date
End If
End Sub
The intended purpose of this macro is to enter today's date into column "C" when a change is made to a cell in Column "A" or "B". I try to use the Row of the cell that is changed in Column "A" or "B" in order to designate what cell I would like to change in Column "C" (i.e. if I change A2 or B2, Cell C2 should have today's date). However, the above macro is placing the date in the wrong cell and column depending on what cell I choose. For instance, if I make changes to cell A2, the date in C3 is changed (the date in C2 should be changed). And when I make changes to cell B2, the date in D3 is changed (the date in C2 should be changed). Oddly enough, when I make changes to cell A1 (title row), it works (i.e. Cell C1 is changed to show today's date), but I would rather it did not take into account changes to the title row (row 1).
Any assistance is much appreciated.
Thanks,
Godfrey
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 1 Or Target.Column = 2 Then
MsgBox "You just changed " & Target.Address
MsgBox "You just changed Row " & Target.Row
MsgBox "I would like to change the date in Cell " & Target.Range("C" & Target.Row).Address
Target.Range("C" & Target.Row).Value = Date
End If
End Sub
The intended purpose of this macro is to enter today's date into column "C" when a change is made to a cell in Column "A" or "B". I try to use the Row of the cell that is changed in Column "A" or "B" in order to designate what cell I would like to change in Column "C" (i.e. if I change A2 or B2, Cell C2 should have today's date). However, the above macro is placing the date in the wrong cell and column depending on what cell I choose. For instance, if I make changes to cell A2, the date in C3 is changed (the date in C2 should be changed). And when I make changes to cell B2, the date in D3 is changed (the date in C2 should be changed). Oddly enough, when I make changes to cell A1 (title row), it works (i.e. Cell C1 is changed to show today's date), but I would rather it did not take into account changes to the title row (row 1).
Any assistance is much appreciated.
Thanks,
Godfrey