Cell Value Replacement

When the cell(A1) value is > than the cell(A2) value, I need to have cell(A2)=cell(A1).

THE PROBLEM: How can I replace the cell(A2) value with the cell(A1) value when the test includes the cell(A2) address? I.E. If(A1>A2,A2=A1).

LibreOffice Version: 6.4.7.2 (x86)
Build ID: 639b8ac485750d5696d7590a72ef1b496725cfb5
CPU threads: 8; OS: Windows 10.0 Build 18363; UI render: default; VCL: win;
Locale: en-CA (en_CA); UI-Language: en-US
Calc: threaded

You can’t replace a cell value by a formula.

Thank you for your answer. I have tried saving INDIRECT(A1) and also INDIRECT(“A1”) into cell A3 but If(A1>A2, A2=A3) also gives the same “Err 508” error message.

You can have a third cell (e.g. A3) evaluating: =IF(A1>A2;A1;A2) (Show me A1 if it is greater than A2, otherwise show me A2)

“=IF(A1>A2,A1,A2)” in cell A3 does the same as ":INDIRECT(A1) or INDIRECT(“A1”) in cell A3 . . . “error message Err 508”.when I try to save A3 to A2.

… when I try to save A3 to A2.

What?! - Start reading LibreOffice Calc Guide

Hi @gemarsh, follows a suggestion with macro.

test file|attachment

The macro is linked to Spreadsheet Events, Content changed.

Sub xhk ( oCelula )
    ' Testar se o objeto selecionado é uma célula individual
    If oCelula.ImplementationName <> "ScCellObj" Then Exit Sub
    If Right(oCelula.AbsoluteName,4) = "$A$1" Then
GoToCel "$A$1"
Dim oSel as Object
oSel = ThisComponent.getCurrentSelection()
Var1 = oSel.getString()
GoToCel "$A$2"
oSel = ThisComponent.getCurrentSelection()
Var2 = oSel.getString()
		If Var1 > Var2 Then
			GoToCel "$A$2"
			EnterString Var1
		End if
    End If  
End Sub

Sub EnterString ( xDig$ ) 
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "StringName" : args1(0).Value = xDig
CreateUnoService("com.sun.star.frame.DispatchHelper") _
.executeDispatch(ThisComponent.CurrentController _
.Frame, ".uno:EnterString", "", 0, args1())
End Sub

Sub GoToCel ( xLocal$ ) 
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint" : args1(0).Value = xLocal
CreateUnoService("com.sun.star.frame.DispatchHelper") _
.executeDispatch(ThisComponent.CurrentController.Frame _
, ".uno:GoToCell", "", 0, args1())
End Sub 

ATTENTION: If you would like to give more details to your question, use edit in question or add a comment below. Thank you.

If the answer met your need, please click on the ball Descrição da imagem to the left of the answer, to finish the question.

Thank you for suggesting and providing a Macro solution.

I suspect that the solution will need to be a Macro solution, but hoping there might be a solution using Formulas and Functions.

I will need a fair amount of time to learn/translate/interpret/understand the Calc Guide, Chapter 12 Macros but, I think, it will be time well spent and the Macro code that you have provided will help.

By formula and function I believe it is not possible, because the value of the cell depends on itself.

“=IF(A1>A2,A1,A2)” in cell A3 does the same as ":INDIRECT(A1) or INDIRECT(“A1”) in cell A3 . . . “error message Err 508”.when I try to save A3 to A2.

Your formula should work typed directly into A2. It is usually reliable, but it may be unstable in some situations.

For it to work, you need to allow circular references, which is connected to iterative calculations. So what you need to do is to enable iterations. (Click link for guide.)

This is perhaps simpler and more portable than @schiavinatto’s suggested macro. His approach will most likely give a more stable/reliable solution.

Thank you for your suggestion but putting the formula { =IF(A1>A2,A1,A2) } into cell A2 generates the “Err 508” Error Message.