O. Borodai
O. Borodai

Reputation: 23

Formula to show the highest value another cell ever reached

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

Answers (2)

D_Bester
D_Bester

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

Gary's Student
Gary's Student

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:

  1. right-click the tab name near the bottom of the Excel window
  2. select View Code - this brings up a VBE window
  3. paste the stuff in and close the VBE window

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:

  1. bring up the VBE windows as above
  2. clear the code out
  3. close the VBE window

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

Related Questions