View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Using VBA functions in Worksheet cell data validation

Andrew,
You don't show your code but I knocked up this little function which is
similar to what you describe

Function IsValid(rng As Range)
If rng.Count 1 Then
IsValid = CVErr(xlValue)
Else
IsValid = (rng.Value = 0 And rng.Value <= 100 And Not
IsEmpty(rng.Value))
End If

End Function

If you put =IsValid(B3) in A3 it reruns TRUE or FALSE depending upon the
value.

How does it compare to yours?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Andrew" wrote in message
...
I wish to validate the data in cell B3. I can readily set up a custom
validation using a formula such as =AND(B3=0, B3<=100)

I would like to use a VBA function that I have written called IsValid().
However, if I attempt to enter a custom validation formula of

=IsValid(B3)
I receive the message "a named range you specified cannot be found".

Where am I going wrong? Can't I reference a VBA function in this way?

The function appears to work if I use it in a normal Worksheet formula.

For
example, if I enter =IsValid(A3) in cell A4 then A4 correctly displays
either TRUE or FALSE depending on the value in A3.