Forum Discussion
Is it possible to record data in a cell whenever another specific data cell changes?
- Mar 08, 2021
The following will work in the desktop versions of Excel (for Windows and MacOS), not in the online version, nor in the versions for Android and iOS.
Let's say you want to apply this to cells A2:A100.
Right-click the sheet tab of the worksheet.
Select 'View Code' from the context menu.
Copy the following code into the worksheet module:
Private Sub Worksheet_Change(ByVal Target As Range) Dim rng As Range Dim dtm As String If Not Intersect(Range("A2:A100"), Target) Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False For Each rng In Intersect(Range("A2:A100"), Target) If IsDate(rng.Value) Then dtm = Format(rng.Value, "dd.mm.yyyy") If Not rng.Offset(0, 1).Value Like "*" & dtm Then If rng.Offset(0, 1).Value = "" Then rng.Offset(0, 1).Value = dtm Else rng.Offset(0, 1).Value = rng.Offset(0, 1).Value & " / " & dtm End If End If End If Next rng Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub
Switch back to Excel.
Save the workbook as a macro-enabled workbook (.xlsm).
Make sure that you allow macros when you open the workbook.
The following will work in the desktop versions of Excel (for Windows and MacOS), not in the online version, nor in the versions for Android and iOS.
Let's say you want to apply this to cells A2:A100.
Right-click the sheet tab of the worksheet.
Select 'View Code' from the context menu.
Copy the following code into the worksheet module:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim dtm As String
If Not Intersect(Range("A2:A100"), Target) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each rng In Intersect(Range("A2:A100"), Target)
If IsDate(rng.Value) Then
dtm = Format(rng.Value, "dd.mm.yyyy")
If Not rng.Offset(0, 1).Value Like "*" & dtm Then
If rng.Offset(0, 1).Value = "" Then
rng.Offset(0, 1).Value = dtm
Else
rng.Offset(0, 1).Value = rng.Offset(0, 1).Value & " / " & dtm
End If
End If
End If
Next rng
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
Switch back to Excel.
Save the workbook as a macro-enabled workbook (.xlsm).
Make sure that you allow macros when you open the workbook.
- nahumjaimeMar 09, 2021Copper Contributor
Hello HansVogelaar.!!
I'm working on a large company where we have a lot of lines of shipments. We are using Excel Online for updating the ETDs and recording on a column the rolling of these ETDs. I've been watching some videos of how to program a sheet on Excel Online using JS but is it possible to run this same program on Excel Online?
- HansVogelaarMar 09, 2021MVP
VBA does not work in the online version.
I cannot help you with a script that works on the web, sorry.
- nahumjaimeMar 08, 2021Copper ContributorHansVogelaar thank you! This works great!!