4

I'm trying to use my own made function inside custom data validation formula. But for some reason it does not work.

My function:

Public Function IsNumberXValid(x) As Boolean
   IsNumberXValid = IsNumeric(x) And Math.Cos(x) <> 1
End Function

When I put this function inside formula field it shows following warning:

enter image description here

What am I doing wrong?

3
  • Have you tried to Name the formula ?? Commented Oct 9, 2016 at 17:58
  • No, I haven't tried @Gary'sStudent Commented Oct 9, 2016 at 18:09
  • See below.......................... Commented Oct 9, 2016 at 19:26

1 Answer 1

6

With normal worksheet functions, it is easy to apply DV:

enter image description here

It is slightly more complex with a UDF() This approach uses a "helper" cell.

I begin with a tiny UDF():

Public Function IsPrime(L As Long) As Boolean
    arr = Array(5, 7, 11)
    IsPrime = False
    For Each a In arr
        If L = a Then
            IsPrime = True
            Exit Function
        End If
    Next a
End Function

The UDF() returns True for a couple of inputs. I want to apply DV to cell D1 using the udf() as a rule.

I am using cell E1 as my "helper". In cell E1 I put my UDF():

=IsPrime(D1)

enter image description here

Next I Name my "helper" cell:

enter image description here


Finally, I return to cell D1 and apply the DV:

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Interesting approach!
@EdgarsŠturms I am using Excel 2007 on a Win 7 machine............does this work for you ??
Is there also a way to get this to work without a helper cell?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.