I have a spreadsheet that I need column B to automatically populate with the date and time when columns C-K are updated. There are columns further than K which I don't want to trigger the update code.
Firstly I used the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
i = Target.Row
Dim t As String
t = VBA.Now
Cells(i, 2) = t
End Sub
This didn't work for my situation as this updates for any changes in the row. The advantage of this was that users could not type over these cells preventing the VBA from entering the date updated.
To enable trigger for just the selected rows, I went to the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("C6:K43")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
Dim i As Integer
i = Target.Row
Dim t As String
t = VBA.Now
Cells(i, 2) = t
End If
End Sub
This is, however, now able to be typed over by users and no longer works.
I have tried locking the cells but then the VBA can't work. I also tried using an offset formula but this doesn't work due to the range of cells being more than 1 column.
Any suggestions before I tear my hair out???