Excel Test Formula

  • Thread starter Thread starter Lee
  • Start date Start date
L

Lee

I know this should be simple but I can't make it work.

If cell (A1) is greater cell (A2), place result in (A2)

Thank You

Lee
 
I can only think of a worksheet change event.
right click on sheet tab>view code>insert this>save
will ONLY work for a change made in cell A2

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$A$2" Then Exit Sub
If Target.Offset(-1) > Target Then Target.Offset (-1)
End Sub
 
This would require a circular formula in A2. This usually causes an error
(although you can allow it). I would suggest using a macro

Private Sub Worksheets_Calculate()
If range("A1").Value > Range("A2").Value then
range("A2").Value = Range("A1").Value
End if
End Sub

Right click on the sheet tab and select view code. Paste in/write code
similar to the above.
 
If Target.Offset(-1) > Target Then Target.Offset (-1)

correct to
If Target.Offset(-1) > Target Then target=Target.Offset (-1)
 
Back
Top