+ Reply to Thread
Results 1 to 7 of 7

Data validation with IF condition

  1. #1
    Registered User
    Join Date
    08-30-2016
    Location
    India
    MS-Off Ver
    Office 2013
    Posts
    7

    Data validation with IF condition

    Hello, I have created Yes/No drop down options in cell B2. If Yes is selected, Cell C2 should show up 3 options from drop down (data validation list). If No is seleced in cell B2, Cell C2 should show up as "Not applicable". How can I get this result? Please suggest.
    My trial :

    In Cell C2>data validation>list and in source, i typed the below formula :

    =If(B2="No", "NA", Sheet2!Frequency) but it says "The source must be a delimited list or a reference to single row or column". I have already created a reference of 3 options for cell C2 by naming the range as "frequency".
    Last edited by G.Madhavi; 09-15-2016 at 03:18 AM.

  2. #2
    Forum Contributor
    Join Date
    02-26-2014
    Location
    Aylsham, Norfolk, UK
    MS-Off Ver
    Excel 365
    Posts
    126

    Re: Data validation with IF condition

    Are the three options from the Yes result always the same? or do they vary depending on other cell data. (Just to clarify)

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Data validation with IF condition

    Thats not the way DV works

    With DV, you select the cell, and a list of values appears - select 1 of them

    To show something else if another cell contains something (no), you would need a formula in C2. But when you select something from te DV, that formula would be over-written
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Data validation with IF condition

    The only way I can see to do this is with VBA. The code needs to check if 'Yes' or 'No' is in B2, then either apply DV or enter 'NA'.
    I'm sure the following code could be compacted/tidied up a bit (I'm not a VBA expert) but it will work, with the list for your 'Frequency' DV in cells B1:B3 of a sheet called 'Drop-down entries'. It will only run when cell B2 is changed.
    Please Login or Register  to view this content.
    To use this code, click 'Alt-F11' to enter the VB-Editor. Right click on the name of the sheet you're working on (for example 'Sheet2 (Working Sheet)' ) and select 'View Code'. Copy the code above and paste it into the window on the right.

    If you copy the code into your file, all you should need to do is change the range for the DV for C2 - in other words, change the bit in red:
    Please Login or Register  to view this content.
    The file will need to be saved as a macro-enabled workbook (.xlsm) for the code to run, and macros will have to be enabled.

    Attached is a file with this code working. B2 and C2 are on the sheet called 'Working Sheet'. The lists for drop-down are on the sheet 'Drop-down entries' - there's 'Yes' and 'No' in A1:A2 (used for B2 on the Working Sheet) and 'Daily' 'Weekly' 'Monthly' in B1:B3 (used for the DV on C2 when 'Yes' is selected).

    Hope that helps.
    Regards,
    Aardigspook

    I recently started a new job so am a bit busy and may not reply quickly. Sorry - it's not personal - I will reply eventually.
    If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark this Thread as Solved'.
    If you use commas as your decimal separator (1,23 instead of 1.23) then please replace commas with semi-colons in your formulae.
    You don't need to give me rep if I helped, but a thank-you is nice.

  5. #5
    Forum Contributor
    Join Date
    02-26-2014
    Location
    Aylsham, Norfolk, UK
    MS-Off Ver
    Excel 365
    Posts
    126

    Re: Data validation with IF condition

    I have done it a slightly different way without the need for VB, just using formulas, however it means creating a separate sheet specifically for that and other "data".

    See the attached.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Data validation with IF condition

    @llamafarmer
    I considered that approach first, but went with VBA for two reasons:
    1. the OP asked for 'NA' to appear in C2 if 'No' was selected - I assumed this was to be entered in the cell, not in a drop-down;
    2. if 'Yes' is selected in B2, then 'Option1' in C2, then 'No' is selected in B2, the 'Option1' remains in C2 until it is actually changed - I assumed the OP would like the cell to be 'reset' when either Yes or No was selected.
    I might be wrong, in which case your solution is good.

  7. #7
    Forum Contributor
    Join Date
    02-26-2014
    Location
    Aylsham, Norfolk, UK
    MS-Off Ver
    Excel 365
    Posts
    126

    Re: Data validation with IF condition

    @Asrdigspook
    I never thought about it from that point of view. I guess that's why we have a forum, certainly my knowledge of VB is no where near good enough to find a solution, hence why I contributed what I could, we'll call it paying it forward as I'm passing on knowledge I gained from this forum ;D

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. data validation with condition
    By Tortus in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 06-03-2016, 02:50 PM
  2. If and Then Condition, Data Validation
    By aaron.mendes in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-03-2014, 04:25 AM
  3. How to use a condition on data validation
    By murchy in forum Excel General
    Replies: 5
    Last Post: 10-30-2013, 12:39 PM
  4. [SOLVED] Data validation based on condition
    By Pavan.Sada.PS in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-17-2013, 09:56 AM
  5. IF THEN condition with data validation
    By Dang-er in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-15-2013, 10:24 AM
  6. Data Validation with condition
    By Jaai001 in forum Excel General
    Replies: 6
    Last Post: 06-04-2011, 12:21 AM
  7. IF condition in Data Validation
    By e4excel in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 03-04-2011, 01:26 PM

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