MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 2nd, 2002, 10:48 AM   #1
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Am trying to get a data validation to work. Has a few conditions.

I want to Validate A1, B1, and C1 as follow

A1 must be either Y or N.
B1 must be either Y or N.
C1 must be a numerical Value.

Only A1 or B1 can have a Y or N at any one time.

If A1 or B1 has a Y or N, C1 can only be 0. If A1 AND B1 are empty, C1 can be any number.

Any ideas?
Cosmos75 is offline   Reply With Quote
Old Apr 2nd, 2002, 11:20 AM   #2
IML
MrExcel MVP
 
Join Date: Feb 2002
Location: Denver, CO
Posts: 1,744
Default

[quote]
On 2002-04-02 09:48, Cosmos75 wrote:



A1 must be either Y or N.
B1 must be either Y or N.
C1 must be a numerical Value.

Only A1 or B1 can have a Y or N at any one time.

a1
=AND(OR(A1="y",A1="n"),A1<>B1)
B1
=AND(OR(B1="y",B1="n"),A1<>B1)
C1
=IF(COUNTIF(A1:B1,"Y")+COUNTIF(A1:B1,"n"),C1=0,ISNUMBER(C1))

Under custom would seem to do what you want. But using this validation, it seems your really limiting what can be put into B1 based on A1 etc. Once N is in A1, B1 can only be unchanged (blank) or Y unless your user blanks out A1 or pastes an item in B1 (which is a limitation of valadation). Just guessing, but it sounds like a more robust vba solution may be needed depending what you want to accomplish...

good luck
IML is offline   Reply With Quote
Old Apr 2nd, 2002, 11:35 AM   #3
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

I also need it for A1 and B1 such that C1=0 so I tried this:

a1
=AND(OR(A1="y",A1="n"),A1<>B1,C1=0)

It works if there is something in B1. But if I enter a value in C1, and then enter Y or N in A1, I don't get an error message???

[ This Message was edited by: Cosmos75 on 2002-04-02 10:36 ]
Cosmos75 is offline   Reply With Quote
Old Apr 2nd, 2002, 11:41 AM   #4
IML
MrExcel MVP
 
Join Date: Feb 2002
Location: Denver, CO
Posts: 1,744
Default

Quote:
On 2002-04-02 10:35, Cosmos75 wrote:
I also need it for A1 and B1 such that C1=0 so I tried this:

a1
=AND(OR(A1="y",A1="n"),A1<>B1,C1=0)

It works if there is something in B1. But if I enter a value in C1, and then enter Y or N in A1, I don't get an error message???

[ This Message was edited by: Cosmos75 on 2002-04-02 10:36 ]
If I understand you right, the problem isn't with the formula, it is with validation itself. I'm not sure the best way to describe this, but it will only work with the data you have as of the moment you enter it. In other words, if you have validation set up only to allow the value of A1 in a cell and A1 = 4, you can only put a 4 in the cell. But if you know change a1 to 9, you won't get an error for what you previous put in. Does this make sense, or am I totaling missing the point?
IML is offline   Reply With Quote
Old Apr 2nd, 2002, 11:48 AM   #5
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Here's some examples:

1. Say
A1 is Empty
B1 is Empty
C1 is equal to 0

If I enter Y or N in A1, I want that to be OK.

2. Say
A1 is Empty
B1 is Empty
C1 is equal to 4

If I enter Y or N in A1, I want data validation to stop me from doing so.

3. Say
A1 is Empty
B1 is equal to Y
C1 is equal to 0

If I enter Y or N in A1, I want data validation to stop me from doing so.

I hope that clears it up. Sorry for not doing a better job of explaining.
Cosmos75 is offline   Reply With Quote
Old Apr 2nd, 2002, 11:49 AM   #6
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

A1 must be either Y or N.
B1 must be either Y or N.
C1 must be a numerical Value.

Hi
If these cells are the ones recieving the data then put this in your sheet code mod.

'
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Select Case Target.Row
Case 1 To 2
If Target.Value <> "Y" And Target.Value <> "N" Then
MsgBox "Invalid Entry - Must Enter 'Y' or 'N'."
Application.EnableEvents = False
Target.ClearContents
Application.EnableEvents = True
Target.Select
Exit Sub
End If
Case 3
If Not IsNumeric(Target.Value) Then
MsgBox "Invalid Entry - Must Enter a Number."
Application.EnableEvents = False
Target.ClearContents
Application.EnableEvents = True
Target.Select
Exit Sub
End If
Case Else: Exit Sub
End Select
End If

End Sub
'

Have a nice day!
Tom
Tom Schreiner is offline   Reply With Quote
Old Apr 2nd, 2002, 11:59 AM   #7
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

TsTom,

What do I modify to change what you have for columns A:C to a range, for example, A10:C25??

Thanks!
Cosmos75 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 01:19 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes