Even though you have tried to bury the circular reference inside of the UDF, Excel still knows that there is a circular reference. You either need to enable iteration (Excel options) or you need to eliminate the circular logic (at least in the spreadsheet).
One advantage of enabling iteration, is that you can accomplish this without any VBA at all. =IF(condition,formula,reference to current cell). The main disadvantage to enabling iteration is, if you ever accidentally create a circular reference, you will no longer get the circular reference warning.
If you decide not to enable iteration, then you need to do something to eliminate the circular logic from the spreadsheet. In this case, that probably means processing the If condition in VBA (maybe in a calculate event procedure).
Private Sub Worksheet_Calculate()
If (condition) then
retrieve new value
Else
retain old value
End If
End Sub
Your choice how you would prefer to do this. We would be able to be more specific in our help if you provide a sample file as suggested.
Bookmarks