Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Using VBA functions in Worksheet cell data validation

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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
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.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Using VBA functions in Worksheet cell data validation

Bob Phillips wrote:
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?


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)




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using VBA functions in Worksheet cell data validation


Can you post your IsValid function cod

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Using VBA functions in Worksheet cell data validation

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)




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using VBA functions in Worksheet cell data validation


Function IsValid(Num As Variant) As Boolean
select case num
case 0 to 100
isValid = true
case else
isValid =false
end select
End Function


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

  #7   Report Post  
Posted to microsoft.public.excel.programming
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)




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Using VBA functions in Worksheet cell data validation

mudraker wrote:
Function IsValid(Num As Variant) As Boolean
select case num
case 0 to 100
isValid = true
case else
isValid =false
end select
End Function


Thanks. However, it's not writing the function that's my problem. It's the
fact that you appear to not be able to use a user define VBA function in
Data Validation.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation Data using Validation Table cell range..... Dermot Excel Discussion (Misc queries) 16 January 5th 10 09:35 PM
Data Validation within a worksheet ChrisGu Excel Discussion (Misc queries) 0 August 7th 09 05:17 PM
Data Validation to different worksheet Gord Dibben Excel Discussion (Misc queries) 2 October 16th 07 10:14 PM
How can i put data Validation on a different worksheet Joe Black Excel Discussion (Misc queries) 6 October 29th 06 09:19 PM
Data Validation Combine Functions Paul Moles Excel Worksheet Functions 2 August 5th 06 03:18 PM


All times are GMT +1. The time now is 04:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"