Forum Discussion
Saving updated cell values in new cells before it refreshes.
- Jan 16, 20181. Make sure Excel calculates when cell A5 changes by placing a formula like =A5 in any cell on that sheet
2. Right-click the sheet's tab and choose "View code"
3. paste this code:
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
Me.Range("M" & Me.Rows.Count).End(xlUp).Offset(1).Value = Me.Range("A5").Value
Application.EnableEvents = True
End Sub
Mind you, this also will copy the value of cell A5 if you manually hit F9 or if something else causes a calculation in our file.
It is triggered by a web query that refreshes every 60 minutes. The cell value for A5 is changed every 60 minutes. I want to be able to save every value in other cells that don't refresh.
- JKPieterseJan 16, 2018Silver Contributor1. Make sure Excel calculates when cell A5 changes by placing a formula like =A5 in any cell on that sheet
2. Right-click the sheet's tab and choose "View code"
3. paste this code:
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
Me.Range("M" & Me.Rows.Count).End(xlUp).Offset(1).Value = Me.Range("A5").Value
Application.EnableEvents = True
End Sub
Mind you, this also will copy the value of cell A5 if you manually hit F9 or if something else causes a calculation in our file.- karanmahajanSep 26, 2024Copper Contributor
JKPieterse
is there a way to save the updated values on different cells each time with a timestamp next to it?- JKPieterseSep 26, 2024Silver Contributor
karanmahajan Depends. Please explain your exact requirements.
- Marco_NLSep 05, 2022Copper Contributor
Thank you for the code! It works very well!
I've adapted it to copy two columns when the calculation changes, but is there a way that it puts it in the next free column when the result changes again? To keep track of all the changes made?
Hope you can help!
Kind regards,
MarcoPrivate Sub Worksheet_Calculate()
Application.EnableEvents = False
Me.Range("AA" & Me.Rows.Count).End(xlUp).Value = Me.Range("H:H").Value
Me.Range("AB" & Me.Rows.Count).End(xlUp).Value = Me.Range("I:I").Value
Application.EnableEvents = True
End Sub
- LisaT760Mar 02, 2022Copper Contributor
How do I change the macro if I have data in cells B5, C5 and D5 as well?
- JKPieterseMar 02, 2022Silver Contributor
LisaT760 That would become something like this:
Private Sub Worksheet_Calculate() Application.EnableEvents = False Me.Range("M" & Me.Rows.Count).End(xlUp).Offset(1).Resize(,4).Value = Me.Range("A5:D5").Value Application.EnableEvents = True End Sub