Reputation: 23
I have cell with number A1, how create another cell (A2) with highest number of A1? For example: A1 = 10 A2 = 10, then i change A1 to 20 A2 = 20, then i change A1 = 12 but A2 still 20. It means if A1 greater than previous A1 it should be write to A2
Upvotes: 1
Views: 1483
Reputation: 5911
You can absolutely do that. The number you want to save is in cell A1. Place this formula in cell A2 intentionally creating a circular reference.
=IF(A1>A2,A1,A2)
You need to enable iterative calculation in File > Options > Formulas > Enable iterative calculation.
Anytime a number in A1 is higher, it will save that number. It will ignore numbers with lower value. It even saves the number when saved and reopened.
See the example of a timestamp using a circular reference.
Upvotes: 0
Reputation: 96753
Place the following event macro in the worksheet code area:
Private Sub Worksheet_Calculate()
newval = Range("A1")
If Range("A2") = "" Then
Else
If newval <= Range("A2") Then Exit Sub
End If
Application.EnableEvents = False
Range("A2") = newval
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx
To remove the macro:
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!
Upvotes: 1