By circumvent, do you mean like this.
Put this in a normal module
Public CellsToColor As New Collection
Public ColorOfCells As New Collection
Function CellOfColor(value_to_show As Variant, _
Optional color_index As Long = xlNone, _
Optional range_to_color As Range, _
Optional color_self = True) As Variant
CellOfColor = value_to_show
If color_index < 1 Or 56 < color_index Then color_index = xlNone
If color_self Then
With Application.Caller
On Error Resume Next
CellsToColor.Add Item:=.Cells, key:=.Address(, , , True)
ColorOfCells.Add Item:=color_index, key:=.Address(, , , True)
On Error GoTo 0
End With
End If
If Not range_to_color Is Nothing Then
With range_to_color
On Error Resume Next
CellsToColor.Add Item:=.Cells, key:=.Address(, , , True)
ColorOfCells.Add Item:=color_index, key:=.Address(, , , True)
On Error GoTo 0
End With
End If
End Function
And this in the ThisWorkbook code module
Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Dim oneCell As Range
If CellsToColor.Count > 0 Then
On Error Resume Next
For Each oneCell In CellsToColor
oneCell.Interior.ColorIndex = ColorOfCells(oneCell.Address(, , , True))
Next oneCell
On Error GoTo 0
End If
Set CellsToColor = Nothing
Set ColorOfCells = Nothing
End Sub
In the attached, C1 holds the formula
=CellOfColor($A1+1, IF(B1="x",33, IF(B1="y",39,0)))
so that the value shown in the C1 is A1+1,
if B1="x", C1's interior color index is 33,
if B1="y", C1's interior color index is 39.
if B1 contains any other value C1 has xlNone as its interior color.
Entering a range for the optional range_to_color argument will color that other range.
Setting the optional color_self to FALSE will color the range_to_color, but not the cell holding the formula.
The trick is that
1) while a UDF cannot change a cell's color*, the Calulate event can.
2) a UDF can change a Public variable (a collection in this case) which can be used to "pass arguments" to the Calculate event
3) the Calculate event runs after a UDF.
*-This restriction applies only when the UDF is called from a worksheet. A UDF called from a VB routine can change a cell's color. (i.e. If Application.Caller is a range object then the UDF can not change a cell's color, otherwise it can.)