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 Oct 25th, 2008, 12:09 AM   #1
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Data Validation List and Custom formula in 1 cell

Dear Smartest Excelers In The World,

Is there a way to have Data Validation List and Data Validation Custom formula in the same formula?

Here is the complete problem description:

1) I made a list of 20 first-names of people on Sheet3, one first-name per cell, no formulas or anything on Sheet3, it's all typed letter by letter.

2) I named those cells on Sheet3 NAMES so that I can use Data Validation on it afterwards

3) I made 15 data validation cells on sheet1, each one is set to allow: LIST and the source for each one is NAMES

4) I'm happy because in each of those data validation cells on Sheet1 I have a dropdown list allowing me to choose amongst any of the firstnames on sheet3

5) I'm unhappy because I can choose one firstname in one data validation cell in sheet1 AND THE SAME ONE in another data validation cell in sheet1
(And this is for a timetable so I don't want 2 firstnames to be able to have the same timetable)

6) I found a method for disallowing duplicates amongst all my data validation cells: (hypothesis: let's say my 15 Data Validation cells on sheet1 are in A1:A15)
I select A1 then I select A1:A15, I go to DATA VALIDATION, I allow CUSTOM, and in SOURCE I put: =COUNTIF($A$1:$A$15,A1)=1

7) Now I cannot put the SAME firstname, in 2 different cells amongst my15 data validating cells in sheet1 BUT I lost my drop down list!!!

8) I want both at the SAME TIME in each of my 15 data validation cells on sheet1!!! (A dropdown data validation list AND disallow duplicates amongst those 15 data validation cells on sheet1)

Any ideas?
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Oct 25th, 2008, 12:17 AM   #2
mikerickson
MrExcel MVP
 
mikerickson's Avatar
 
Join Date: Jan 2007
Location: Davis CA
Posts: 8,453
Default Re: Data Validation List and Custom formula in 1 cell

Something like this should work
Validate Sheet1!A1 with this and copy the validation to the other cells of Sheet1!A1:A15
=AND( ISNUMBER(MATCH(A1,NAMES,0)), (COUNTIF($A$1:$A$15,A1)=1)) will validate things.

But you don't have a List to choose from.

you could leave the validation on list and put this in the code module for
Code:
Sheet1Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 And Not (Application.Intersect(Target, Range("A1:A15") Is Nothing)) Then
    If 1 < Application.CountIf(Range("A1:A15"), Target.Value) Then
        Application.EnableEvents = False
            Target.ClearContents
            MsgBox "No duplicates allowed in A1:A15"
        Application.enableevnets = True
    End If
End If
End Sub
mikerickson is offline   Reply With Quote
Old Oct 25th, 2008, 12:42 AM   #3
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: Data Validation List and Custom formula in 1 cell

Dear mikerickson,

Thank you so much for answering so quickly!

I just tried the code and got a "Compile error: type mismatch" error and the "Private Sub Worksheet_SelectionChange(ByVal Target As Range)" part was a yellow color and the "Is Nothing" part was highlighted.

Any ideas?

This is the code that I pasted in sheet 1:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count = 1 And Not (Application.Intersect(Target, Range("A1:A15") Is Nothing)) Then
If 1 < Application.CountIf(Range("A1:A15"), Target.Value) Then
Application.EnableEvents = False
Target.ClearContents
MsgBox "No duplicates allowed in A1:A15"
Application.enableevnets = True
End If
End If
End Sub
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Oct 25th, 2008, 12:53 AM   #4
mikerickson
MrExcel MVP
 
mikerickson's Avatar
 
Join Date: Jan 2007
Location: Davis CA
Posts: 8,453
Default Re: Data Validation List and Custom formula in 1 cell

move the parenthesis
Code:
Not (Application.Intersect(Target, Range("A1:A15")) Is Nothing)
mikerickson is offline   Reply With Quote
Old Oct 25th, 2008, 07:13 AM   #5
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: Data Validation List and Custom formula in 1 cell

Dear Mike,

EXCELlent! That got rid of the Yellow and the error message, but now when I add a duplicate record in A1:A15 on sheet1 it does not prevent it.

I have the code pasted in the sheet1 (sheet1) area. Is that correct?
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Oct 25th, 2008, 07:28 AM   #6
mikerickson
MrExcel MVP
 
mikerickson's Avatar
 
Join Date: Jan 2007
Location: Davis CA
Posts: 8,453
Default Re: Data Validation List and Custom formula in 1 cell

With the correction above and the proper spelling of Events, this worked for me.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count = 1 And Not (Application.Intersect(Target, Range("A1:A15")) Is Nothing) Then
        If 1 < Application.CountIf(Range("A1:A15"), Target.Value) Then
            Application.EnableEvents = False
                Target.ClearContents
                MsgBox "No duplicates allowed in A1:A15"
            Application.EnableEvents = True
        End If
    End If
End Sub
Are events enabled or did it crash with them disabled.

The code module of sheet1 is where that should go.
mikerickson is offline   Reply With Quote
Old Oct 25th, 2008, 07:37 AM   #7
Peter_SSs
MrExcel MVP
Moderator
 
Peter_SSs's Avatar
 
Join Date: May 2005
Location: Macksville, Australia
Posts: 14,217
Default Re: Data Validation List and Custom formula in 1 cell

mgirvin

Here is another method (non vba) that I think will do what you want.

Set up Sheet3 with some extra info (see below):
1. Your 'Names' range would be A2:A21 in my setup (though this named range will not be used in my solution)

2. B1 houses a 0, C2 the formula shown.

3. B2 and D2 formulas copied down to row 21.

4. Insert|Name|Define... In the 'Names in workbook:' box type RemainingNames and in the 'Refers to:' box type =OFFSET(Sheet3!$D$2,,,Sheet3!$C$2) and click OK

Sheet3

 ABCD
1Orig List0No. AvailableNew List
2Ann 17Bob
3Bob1 Don
4Col  Ern
5Don2 Fay
6Ern3 Gil
7Fay4 Hal
8Gil5 Ian
9Hal6 Ken
10Ian7 Len
11Jan  Mel
12Ken8 Ned
13Len9 Ono
14Mel10 Pat
15Ned11 Que
16Ono12 Ron
17Pat13 Sam
18Que14 Ted
19Ron15  
20Sam16  
21Ted17  

Spreadsheet Formulas
CellFormula
B2=IF(ISNA(MATCH(A2,Sheet1!$A$1:$A$15,0)),LOOKUP(9.99999999999999E+307,B$1:B1)+1,"")
C2=MAX(B2:B21)
D2=IF(ROWS(D$2:D2)>$C$2,"",INDEX($A$2:$A$21,MATCH(ROWS(D$2:D2),$B$2:$B$21,0)))


Excel tables to the web >> Excel Jeanie HTML 4



On Sheet1
5. Make your data validation as shown.

Sheet1

 AB
1Col 
2Jan 
3Ann 
4  
5  
6  

Data Validation in Spreadsheet
CellAllowDatasInput 1Input 2
A1List =RemainingNames 


Excel tables to the web >> Excel Jeanie HTML 4
__________________
Hope this helps, good luck.
Peter
Peter_SSs is online now   Reply With Quote
Old Oct 25th, 2008, 09:29 AM   #8
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: Data Validation List and Custom formula in 1 cell

Dear mikerickson,

That worked!!!! Totally EXCELlent! Thank you so much. I am always amazed at all the Excellent Excelers like you that help out!
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Oct 25th, 2008, 09:35 AM   #9
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: Data Validation List and Custom formula in 1 cell

Dear SSs,

That is so amazing!! It's like Magic, what you formulas do! Thank you for the concept of a formula that finds one-more-than-is-in-the-list and also for the formula that creates a shrinking list!

You and Mike and many other MrExcel Excel Excelers are awesome!!!
__________________
Sincerely, Mike Gel Girvin
mgirvin 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 +1. The time now is 01:05 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 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