This is the solution I found on the above question using Tim William magic :
Function cq(thisCel As Range, srcCel As Range) As Variant thisCel.Parent.Evaluate "colorEq(" & srcCel.Address(False, False) _ & "," & thisCel.Address(False, False) & ")" cq = srcCel.Value End Function Sub colorEq(srcCell, destCell) destCell.Interior.Color = srcCell.Interior.Color End Sub
destCell is just a reference to the cell into which the function is called.
interior.color can be exchanged or added using other formatting rules. In this decision, three additional points can be distinguished:
- By storing the calculation of the value in the formula, this stops the possibility of a circular reference when destCell refers to itself. If it is placed in a
sub , it constantly recounts; and - If the format changes only when the initial value is changed, and not in the format, as this is the only trigger for starting UDF and, thus, changing the format;
Application.Caller or Application.ThisCell cannot be integrated, as if it referred to itself and returned a value for itself, it starts an infinite loop or a "circular link". If it is included in the address to create the string, then this works, although in accordance with Tim William's answer.
AER Aug 10 '16 at 5:46 a.m. 2016-08-10 05:46
source share