+ Reply to Thread
Results 1 to 8 of 8

Struggling with wildcards in IF function

  1. #1
    Registered User
    Join Date
    08-27-2015
    Location
    UK
    MS-Off Ver
    2013
    Posts
    4

    Struggling with wildcards in IF function

    Hi All,

    I'm trying to write a checking formula to check responses are valid to a multiple choice question on a separate sheet, which isn't going my way.

    I have attached an example Excel for reference. I'll just go straight into my problem.

    Column A (NS_60_1_1) is a multiple response question and they can answer 1 - 9. Column B (NS_140_1_1) has a criteria of:
    IF Column A = anything that isn't JUST <> 2, 3 or 7, then response should be in Column B (I will call this a valid response). If the response is JUST 2, 3 and/or 7 then Column B should be "NULL" (I will call this an invalid response).

    So example responses (seperated by semi comma per response) for Col. A that would trigger Col. B are: 1; 4; 01,03; 04,07; 01,02,03,04,05,06,07,08,09; Example responses that would skip Col. B would be: 2; 3; 02,07; so on and so on.

    For invalid responses, it's easy. it's just =IF(AND(OR(Service!$A2=2,Service!$A2=3,Service!$A2="02,03",Service!$A2="02,03,07",Service!$A2="02,07",Service!$A2="03,07"),Service!$B2="NULL"),"TRUE1","ERROR") Because there aren't many combinations for the responses (responses ALWAYS go from lowest to highest, never in another order). For valid responses there are too many however. I would be typing something like: Service!$A2="01,04",Service!$A2="01,02",Service!$A2="04,05,07",Service!$A2="02,04,05,06,07",Service!$A2="02,04" so on and so on.

    My initial solution was: =IF(AND(OR(Service!$A2=2,Service!$A2=3,Service!$A2="02,03",Service!$A2="02,03,07",Service!$A2="02,07",Service!$A2="03,07"),Service!$B2="NULL"),"TRUE1",IF(AND(OR(Service!A2="?1*",Service!A2="*4*"),Service!$B2<0),"TRUE2","ERROR")) What this should do is return TRUE1 if invalid responses are chosen, and TRUE2 if invalid responses are chosen, with ERROR there to show all quality issues with the raw data.

    However the wildcards in the 2nd IF function aren't doing with I expect....

    Some useful things to know: valid responses will always contain either 1, 01, 02, 03, 4 or 04. If someone responds with 05 or on wards, it will invalidate the whole questionnaire.
    Invalid responses will never contain numbers other than 2, 3, 02, 03 or 07.

    Can anyone help?

    Thank you!
    Gavin
    Attached Files Attached Files
    Last edited by xgavversx; 08-27-2015 at 10:21 AM.

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Struggling with wildcards in IF function

    You can't use wildcards in logical tests, you would need to use

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    for a result anywhere in the cell, or
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    to find an exact starting position. (=2 at the end or the formula means starts at the second character, so the same as a single "?" wildcard character).

    You might find your task easier if you look into VLOOKUP.

  3. #3
    Registered User
    Join Date
    08-27-2015
    Location
    UK
    MS-Off Ver
    2013
    Posts
    4

    Re: Struggling with wildcards in IF function

    Thanks for the reply. I've realised what I'm trying to do is actually not possible in Excel, so we're going to look into another solution. Thank you again though, I've definitely learned something today

  4. #4
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Struggling with wildcards in IF function

    Quote Originally Posted by xgavversx View Post
    I've realised what I'm trying to do is actually not possible in Excel, so we're going to look into another solution.
    Which part of it do you think is not possible?

    Based on your question and sample, I would say it just needs a little research. Having multiple choices in a single cell is not ideal, but you can work with it.

    If you're finding that you have too many combinations given the variations of "01,02", "1,02", "01;2", etc. Then you might find that this helps.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Not sure what you were trying to do with 'Service!$B2!<0' at the end of your formula, that would only pick up on negative numbers, which doesn't appear to relate to anything in your sheet.
    I've left it the same in my suggestion, but think that it needs to be something else.

  5. #5
    Registered User
    Join Date
    08-27-2015
    Location
    UK
    MS-Off Ver
    2013
    Posts
    4

    Re: Struggling with wildcards in IF function

    What I meant was it's not possible for me to do in Excel at my current level. There's a lot more I need to learn before I try and attempt something like this on my own.

    'Service!$B2!<0'
    The point of this was to find a response other than NULL. I figured seeing as a response in Col. B is a number, it is greater than 0.... I did leave the wrong formula in my example though, because that's a less than symbol! :S Originally I tried "<>NULL" but I guess Excel doesn't like that.

    When I have time today I'm definitely going to take this away and research all these functions and how this formula works. Would the solution be easier for me if I insert 8 columns between Col. A and delimit Col. A with commas maybe? This was also something suggested to me. I don't know if this works in practice though, as this was suggested by someone who works with databases, not Excel. I was hoping to keep all the work to 1 column though.

    Thank you for the knowledge and help

  6. #6
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Struggling with wildcards in IF function

    You almost had it right, it should have been <>"NULL" not "<>NULL"

    The way you tried it is used in excel, but only with countif(s), sumif(s) or averageif(s).

    What you need might not be possible for you in excel, but that's why we're here.

    You can delimit column A, that is effectively what the formula does, to make things more 'uniform' it replaces ; with , and removes any zeros so that you are left with a comma delimited list if single digit numbers, which gives you less variations to try and check.

    One point I will make in case you're not aware, as I get the impression this might be something you need to do. A formula can only show a result in the cell that it occupies, you can't "send" the result to another cell without a formula to override or restrict what users enter. That would need either data validation or vba depending on the requirements.

  7. #7
    Registered User
    Join Date
    08-27-2015
    Location
    UK
    MS-Off Ver
    2013
    Posts
    4

    Re: Struggling with wildcards in IF function

    I think I found the solution, however there's probably junk I don't need in the statement.

    I'll underline what I changed:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    For some reason, wrapping the 0 with double quotations in the second logic check of the AND statement seems to work. I now get TRUE1 and TRUE2 in the correct cells instead of TRUE1 and ERROR. I did some spot checks and it seems to do what I want it to and put ERROR where it needs to go.

  8. #8
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Struggling with wildcards in IF function

    Did you see the comment in my last post about <>"NULL"and "<>NULL" ?

    I would advise being very careful with the use of "0" in a greater than, equal than, or less than situation. As with the above, it works when used correctly, but can be misleading.

    For example "-1" is greater than 9999999999 (no "")

    Excel stores numbers in 2 different ways, number format and text format. Any number in text format, no matter how small, will be greater than the largest number in a proper number format.

    Numbers in text format are sorted 'alphabetically' not numerically, i.e. the number is read from left to right, so in order you would get 1, 11, 12, 123456, 2, 21, etc. Meaning "2" is greater than "123456"

    As with anything, this can be very useful, but also cause problems when used incorrectly.

    A web search for "Excel numbers stored as text" should return more information on this if it's not making sense, and no doubt explain it better than I can.

+ 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. [SOLVED] struggling with 'lookup value in" MATCH function
    By GraemeG in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-10-2015, 08:38 AM
  2. [SOLVED] Struggling with COUNTIFS function returning 0 when value expected
    By vbalearnerdriver in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 07-03-2014, 06:32 AM
  3. Struggling with IF function
    By Pixelmeastro in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-29-2014, 05:14 AM
  4. struggling using index function and cell references
    By nwai in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-13-2014, 05:13 PM
  5. [SOLVED] Struggling to get a small search function working correctly
    By bodhi808 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2013, 08:34 PM
  6. struggling with PMT function
    By apexdad in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-05-2012, 07:13 AM
  7. VBA Coding Help Needed, Struggling to make a workbook function!
    By chriscole412 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2012, 01:51 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