Excel Formula Flag Triggering

时间:2016-02-03 03:06:41

标签: excel excel-formula ms-office

What I'm trying to do in Excel is to figure out a way to trigger a flag after a certain condition has been met.

E.g. I have numbers A and B. A is static while B changes. I also have a Flag f that is initially false. When B>A, f changes to true and stays true regardless of any future value of B.

I was trying to do this with a circular reference, but couldn't get an initial value out of it. Is this possible while only using formulas? I've been trying to avoid using VBA. Any help or point in the right direction would be appreciated.

Thanks

1 个答案:

答案 0 :(得分:1)

A formula based solution with circular references and allowing iterations will be messy. If you can find someone who can create it in the first place, after a while nobody will remember what it does and how to maintain it.

VBA that writes the value into the cell as soon as the condition is met is a much more reliable and maintainable way.

The code would be along the lines of

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B1")) Is Nothing Then
    If Range("F1") = False Then
        If Range("B1") > Range("A1") Then Range("F1") = True
    End If
End If

End Sub