0

Can someone please tell me why this is not working?

Function CHECKERROR1(a As Long, b As Long) As Range
    If a = b Then
    Else
        CHECKERROR1.Font.Color = vbRed
        CHECKERROR1.Value = "ERROR"
    End If
End Function

I want to return a red 'ERROR' when the two numbers don't match

GSerg
  • 76,472
  • 17
  • 159
  • 346
  • A udf can't return a color. – JNevill May 06 '19 at 19:37
  • This is not working because `CHECKERROR1` is `Nothing`, because you never assigned it to a `Range`. If you did assign it to a Range, it would work, unless you [call it from a cell](https://stackoverflow.com/a/3622544/11683). – GSerg May 06 '19 at 19:39
  • Normally you can't but [here](https://stackoverflow.com/a/55993127/6600940) I learned that it might be possible. So, if you tweak my approach you might be able to do that. – Storax May 06 '19 at 19:40
  • You can however use conditional formatting. – JvdV May 06 '19 at 19:40
  • @JvDV: Yes, right, that will probably be the right way to go here. – Storax May 06 '19 at 19:41

0 Answers0