+ Reply to Thread
Results 1 to 10 of 10

IF statement with variable # of conditions

  1. #1
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    IF statement with variable # of conditions

    sample.PNG

    Hi!
    Let me ask for help. I would like to create a function based on IF statement (or possibly other) that returns categories such in red (in attachment) based on multiple conditions like shown below:


    Please Login or Register  to view this content.

    Categories would be defined by populated cells.
    The # of columns and # of categories would be variable.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: IF statement with variable # of conditions

    Personally I'd build a Vlookup table that concatenates the various IF condition tests into a single cell, and in the adjacent column cell enter the result required, e.g.
    ABC

    So for instance in F2 enter "USADenvermildmedium" and in G2 "ABC
    repeat for other conditions and in A2 enter
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    Re: IF statement with variable # of conditions

    Thanks Richard. The Only roadblock I hit with such VlookUp solution is when there are blank cells, which means for example "DEF" would be Londonmildhigh so country can be "any" in dataset.
    By that means EnglandLondonmildhigh <> Londonmildhigh.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: IF statement with variable # of conditions

    In that case make sure that you build in a space, or any character for that matter if a space exists. e.g.

    So to create the first column of the lookup table enter
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    assuming the 'rules matrix is in B1:Enn

    Then the vlookup formula similarly becomes

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

  5. #5
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    Re: IF statement with variable # of conditions

    Hi Richard. Thanks. Issue is rules matrix is not fixed to B:E. Fields, number of fields and their order can be various for each user as they have custom categories. However field names in lookup reference are identical to f. names in data list. I first put the sample reference into formatted table (dynamic named range) which eases the vlookup for variable # of rows. Now the concatenation part is tricky. Probably a loop that goes through row and joins non-blank cells. Next to recognize which cell - fields were joined at every row for vlookup to find match. Unfortunately, I am clueless to put this into practise.

  6. #6
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    Re: IF statement with variable # of conditions

    Sample.xlsm
    In this file I managed to concatenate both values for categories and their respective field names, sheet LookUp reference.
    However I cannot figure out how to concatenate / create a looked-up value on Data sheet, to match and find
    corresponding Category on Lookup reference sheet.
    Last edited by pulsar777; 11-29-2015 at 08:07 AM.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: IF statement with variable # of conditions

    Sorry but your latest workbook isn't clear.

    You imply that the permutation of fields varies but your original code was attempting to create a specific rule.

    If the column B values on the lookup sheet are correct we need to understand the though process and calculation you have made in your mind that allowed you to get these values. If you can explain these 'rules' then coming up with an answer would be a bit easier.

  8. #8
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    Re: IF statement with variable # of conditions

    Sample.xlsm

    I adjusted layout to better imagine the logic.
    By example:
    ABC:
    =Vlookup(data! ITEM & SUBGROUP & LINE_CODE & GROUP, lookup_ref! F:G, 2, 0)
    DEF:
    =Vlookup(data! ITEM & LINE_CODE & GROUP, lookup_ref! F:G, 2, 0)
    - on data sheet, 0477 SUBGROUP instead of blank, but Vlookup = TRUE
    > blank in Lookup_ref = any value on Data sheet (e.g SUBGROUP)
    Following means there won't be 1 rule-based Vlookup but mechanism that looks up against all combinations on lookup_ref sheet.
    Moreover, every user can have different combinations (category definitions) like COUNTRY & DISTANCE, GROUP & ITEM.

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: IF statement with variable # of conditions

    Where does the "ABC" or "DEF" come from in the original data?

  10. #10
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    Re: IF statement with variable # of conditions

    The user defines "ABC", "DEF" etc manually in L. reference.
    Then, data list has computed column, in which "ABC" is retrieved / looked up from that reference.

+ 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. Replies: 2
    Last Post: 07-09-2015, 04:25 PM
  2. [SOLVED] IF Statement Using Several Conditions
    By DDM64 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-28-2013, 09:46 PM
  3. [SOLVED] For Next Statement with If Statement Reducing Upper Variable
    By Break_Point in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-28-2013, 06:30 PM
  4. [SOLVED] If statement with conditions on some....
    By albertc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2012, 06:01 AM
  5. Subtracting - variable conditions
    By Bodz in forum Excel General
    Replies: 4
    Last Post: 07-26-2008, 12:55 PM
  6. if statement with two conditions
    By mkmed in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-03-2007, 09:49 PM
  7. Replies: 3
    Last Post: 06-26-2005, 10:05 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