I have a worksheet that contains several named tables and some "free range" data. In one specific table only (named "TestTable"), each time I change data in one column (column I, "Fee Delta") I would like the neighboring cell (column J, "Change Date") to mark the data / time of the change. Additionally, I would like the code to reference the column names rather than letters, so that if columns are added or deleted the code can adapt. I am close, but need help.
My VBA code works to an extent, but I have two problems:
Here's what I have so far. Any ideas? (And thank you!)
Private Sub Worksheet_Change(ByVal Target As Range)
' Auto Date
Dim Cell As Range
For Each Cell In Target
If Cell.Column = Range("TestTable[Fee Delta]").Column Then
If Cell.Value <> "" Then
Cells(Cell.Row, "J").Value = Now
Else
Cells(Cell.Row, "J").Value = ""
End If
End If
Next Cell
End Sub
My VBA code works to an extent, but I have two problems:
- My code property finds column I by title ("Fee Delta") even when columns are added / removed, but I cannot figure out how to contain its range so that it only works inside the table. Right now, any change I make in column I results in a timestamp in column J, even if it's not in the target table.
- I can't figure out how to reference my target column (J, "Change Date") by name the same way that I could my trigger column.
Here's what I have so far. Any ideas? (And thank you!)
Private Sub Worksheet_Change(ByVal Target As Range)
' Auto Date
Dim Cell As Range
For Each Cell In Target
If Cell.Column = Range("TestTable[Fee Delta]").Column Then
If Cell.Value <> "" Then
Cells(Cell.Row, "J").Value = Now
Else
Cells(Cell.Row, "J").Value = ""
End If
End If
Next Cell
End Sub