Forum Discussion
CHollander
Dec 08, 2022Copper Contributor
limit the "NOW" function.
Is there a way (to have one cell on the top of a row) track the date that a change was made in that row? Or is there away to limit the "NOW" function to a few select cells? For example, =if( there ...
- Dec 12, 2022
Private Sub Worksheet_Change(ByVal Target As Range) Dim rngBereich As Range Dim j As Long Application.EnableEvents = False Set rngBereich = Range("A2:XFD1048576") If Target.Cells.Count > 1 Then GoTo done If Not Application.Intersect(Target, rngBereich) Is Nothing Then If Target.Value <> "" Then j = Target.Column Cells(1, j).Value = Now Else End If End If done: Application.EnableEvents = True Exit Sub End Sub
You can try this code. In the attached file you can enter data in any cell in range A2:XFD1048576. The code then determines the column of the target cell and enters the current day and time in row 1 of the target column.
OliverScheurich
Dec 08, 2022Gold Contributor
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngBereich As Range
Application.EnableEvents = False
Set rngBereich = Range("A2:G2")
If Target.Cells.Count > 1 Then GoTo done
If Not Application.Intersect(Target, rngBereich) Is Nothing Then
If Target.Value <> "" Then
Range("A1").Value = Now
Else
End If
End If
done:
Application.EnableEvents = True
Exit Sub
End Sub
You can try this code. In the attached file you can make a change in any cell in range A2:G2 and the current time is entered in cell A1.
CHollander
Dec 12, 2022Copper Contributor
That was great! The next question is, how do I continue the code throughout the page? I would like that the top cell on each column tracks the most recent update of that column. (a1 tracks column a, b1 tracks column b) if you can help with that it would be a great help😀
- OliverScheurichDec 12, 2022Gold Contributor
Private Sub Worksheet_Change(ByVal Target As Range) Dim rngBereich As Range Dim j As Long Application.EnableEvents = False Set rngBereich = Range("A2:XFD1048576") If Target.Cells.Count > 1 Then GoTo done If Not Application.Intersect(Target, rngBereich) Is Nothing Then If Target.Value <> "" Then j = Target.Column Cells(1, j).Value = Now Else End If End If done: Application.EnableEvents = True Exit Sub End Sub
You can try this code. In the attached file you can enter data in any cell in range A2:XFD1048576. The code then determines the column of the target cell and enters the current day and time in row 1 of the target column.