View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Dick Kusleika[_3_] Dick Kusleika[_3_] is offline
external usenet poster
 
Posts: 599
Default Using VBA functions in Worksheet cell data validation

Andrew

You guessed it. You can't use a UDF in Data Validation (at least not that
I've ever seen). You can use theWorksheet_Change event to validate the data
using your UDF and pretty much emulate what you can do with DV.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Andrew" wrote in message
...
mudraker wrote:
Can you post your IsValid function code


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from
http://www.ExcelForum.com/


My function is:

Function IsValid(Num As Variant) As Boolean
IsValid = (Num = 0 And Num <= 100)
End Function
(the final version will check for various text values as alternatives to
0..100, hence use of Variant)

I have no problem using the function in a formula in a cell (eg.
=IsValid(B3) in cell A3). My problem occurs when I attempt to use the

same
formula for Data Validation in as cell. eg in Cell B3 I select:

Data | Validation | Settings | Allow Custom | Formula =IsValid(B3)

This ought(?) to do the same as the worksheet function:

Data | Validation | Settings | Allow Custom | Formula =AND(B3=0,
B3<=100)