+ Reply to Thread
Results 1 to 15 of 15

Dependent Validation Type

  1. #1
    Registered User
    Join Date
    06-07-2013
    Location
    Greece
    MS-Off Ver
    Excel 2010
    Posts
    10

    Dependent Validation Type

    Hi All,

    I am looking for a way to create a dependent valication for a cell.
    For example if on cell A1 we have the value "List" then the Data Validation on Cell B1 will be a defined List.
    If on Cell A1 we have the value "Number" then the Data Validation for B1 will be numbers from a specified range but not coming from a list.
    If on Cell A1 we have the value "text" then the values in B1 will need to be text.
    I hope this makes some sense.
    Any help would be greatly appreciated.

    Best regards,

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dependent Validation Type

    Data Validation Settings in B1:

    Allow: Custom
    Source: =IF(A1="Number", ISNUMBER(B1), IF(A1="Text", ISTEXT(B1)))
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    06-07-2013
    Location
    Greece
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Dependent Validation Type

    Hi JBeaucaire,

    Thank you very much for the prompt response.
    I am afraid that this suggestion won't work with lists.
    I was wondering whether there is a way to add this feature as well.
    Say have a defined list of values referenced as "List" and then have a drop down option apear on B1 when A1 reads "List"
    Thank you in advance

  4. #4
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Dependent Validation Type

    What you are looking for is an indirect validation

    First you name your list range as list and number range as number

    Suppose you want to put text 'number' in A1 and the dropdown should appear in B1, then use data validation for B1 and put the formula as =INDIRECT(A1)

  5. #5
    Registered User
    Join Date
    06-07-2013
    Location
    Greece
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Dependent Validation Type

    Hi Akhileshgs,

    Again I don't think this will work. What I am looking for is the dynamic creation of a drop down on a cell.
    If I understand you correctly, you are suggesting that I use indirect but select list as my validation type.
    The thing is I want to dynamically have lists or no lists on the cell. However, when there is no drop down the cell value will be controlled. Say if on A1 the value is "Number" then the input on B1 should be a number that follows a defined rule for example any value between 0 and 32 with any decimals allowed. If the value on cell A1 is "Percentage" then the value on B1 can be a percentage from 10 % to 90 %. If the value on A1 is "Long" then the allowed value on B1 can be anything up to 150 characters etc.
    Hope this clarifies things a bit.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dependent Validation Type

    You're putting too many apples into this cart. I don't believe you can accomplish all of that with mere formulas and DV setups. You would have to employ VBA programming on your sheet to dynamically rewrite the DV settings in column B based on what is selected in column A.

    If you'd like help with some VBA, I can move this thread to the VBA forum and we can continue there.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dependent Validation Type

    This macro will accomplish your requirments:

    Please Login or Register  to view this content.
    To add to your workbook:

    1. Open up your workbook
    2. Right-click the sheet tab and select VIEW CODE
    3. Copy and Paste in your code (given above)
    4. Get out of VBA (Press Alt+Q)
    5. Save as a macro-enabled workbook

    The macro is installed and ready to use. It operates on its own. As you make drop down changes in column A, it will apply custom DV settings to column B on that row to match your choice.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-07-2013
    Location
    Greece
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Dependent Validation Type

    Hi JB,
    Thank you very much for this. I suspected there would be some VBA involved to accomplish this.
    I will give this a shot and let you know how it goes.
    Many thanks
    Last edited by JBeaucaire; 06-08-2013 at 09:01 AM. Reason: Removed unnecessary whole-post quote

  9. #9
    Registered User
    Join Date
    06-07-2013
    Location
    Greece
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Dependent Validation Type

    Hi JB,

    I have been testing your suggestion and indeed this seems to be almost done on your example. What I found missing is the option for a drop down with a list of set values.
    Can this be added? I have tried modifying your code with ".Add Type:=xlValidateList" but to no avail. Also on my production spreadsheet the validation reference cell is on column "AR:AR" instead of "A:A" and the cells that required validation are on column "Z:Z" instead of "B:B".
    I understand that this requires some slight modification on your code but i do not know on which point exactly.
    In any case i Have attached the code i came up with for your reference.
    Thanks in advance.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 06-08-2013 at 09:02 AM. Reason: Removed unnecessary quote, please use the REPLY button below, not REPLY WITH QUOTE

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dependent Validation Type

    Tip, turn on the macro recorder, then let it record you applying the data validation LIST to a cell, then turn off the macro recorder. The resulting code should give you snippets and syntax you can adapt into your permanent macro.

    I changed the cell.Offset(, -16) to a style of syntax that is much less cumbersome to read. I also adapted the NUMBER option to allow decimals, you stopped the range at -10 and 10 which would not have allowed decimals ON the -10 and 10 values.

    Lastly, in the code we use the UPPER CASE version of the items in the initial drop down, just to be exact.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-07-2013
    Location
    Greece
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Dependent Validation Type

    Thank you very much JB. And thanks for the tip.
    You have been a great help.
    I will go ahead and do some more testing but I think I am almost there.
    One thing I noticed while testing this is that these rules are not applied if the reference for the validation is the product of a function instead of a user selection.
    To be more specific if we select "Number" on a cell in AR:AR column then the code works. However if the value on the cell in the "AR:AR" column is the product of a vlookup that reads "Number" then the validation is not applied.
    Is there any way to remedy this?
    Again you have been extremely helpful thank you for taking the time to explain these things to me.
    If you feel this post will be better suited in the VBA section please go ahead and move it there.
    Last edited by JBeaucaire; 06-08-2013 at 12:23 PM. Reason: Removed unnecessary whole-post quote... again! ;) Cut it out.

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dependent Validation Type

    Friend, please stop using the REPLY WITH QUOTE button. Use the REPLY button. Nice and clean thread. Use a the quote button if you wish to discuss something specific that's been said, and even then edit it down to just that part. OK? No demerits cause you're new, but do take a moment to read the Forum Rules in the menu bar above, it is very helpful and instructive. Thanks.


    Yes, you are correct. There are many different types of events that can be put into the Sheet module, and the Worksheet_Change event is triggered by a manual change to any cell on the sheet. I do not recommend the Worksheet_Calculate event which would trigger any time any value changed on the sheet including formulaic values because it is not "Targeted" the way the change macro is, so you would have to restructure the macro to examine every cell in column AR and it would most likely lead to a noticable slowing down of your sheet's performance.

    We can do that, if formulas are a must-have, but I predict this will be more cumbersome. Hmm... maybe we could use TWO columns, AR as the one that is being checked, and another column off to the right like AZ where we store the current values in AR, then the worksheet_calculate event goes down AZ and only acts on the row(s) where the value no longer matches AR, acts, then updates AZ so it matches again?

  13. #13
    Registered User
    Join Date
    06-07-2013
    Location
    Greece
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Dependent Validation Type

    I apologise for the replies with quotes.
    I did not catch the first correction you made.
    I see where you are going with this. This could be the way to go but if overall workbook performance is affected I think i can make a few changes and stick with manual change.
    In any case I think it's safe to say that this issue has been resolved for me. So if you would like please go ahead and mark this thread as such.
    Or do i have to do it myself?
    Sorry I am new to the site and am not familiar with overall operation.
    Thanks again for your insight you are a life saver.

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dependent Validation Type

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Thanks.

  15. #15
    Registered User
    Join Date
    06-07-2013
    Location
    Greece
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Dependent Validation Type

    Will do. Many thanks JB.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1