+ Reply to Thread
Results 1 to 8 of 8

IF with multiple logical tests with text displayed if each true

  1. #1
    Registered User
    Join Date
    03-24-2014
    Location
    London, England
    MS-Off Ver
    Excel 2011
    Posts
    8

    IF with multiple logical tests with text displayed if each true

    Hello there,

    I need a formula, I assume using IF as a basis, that enables me to have more than one logical test and display a specific piece of text in the cell if each one is true.

    For example:

    If A1=1, display London, if A2=1, display Paris, if A3=1 display Berlin. But here's the catch - if A1 and A2 both contain 1 then I want "London, Paris" displayed in the cell, and if A1 and A3 both contain 1 then I want "London, Berlin" in the cell.

    Any help would be greatly appreciated, and in practise there are many more than three cells but that's just as an example.

    Thanks,

    Daniel

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: IF with multiple logical tests with text displayed if each true

    Quote Originally Posted by danielball View Post
    there are many more than three cells but that's just as an example.
    You will need a VBA function to do this.

    Are you open to that idea?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  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: IF with multiple logical tests with text displayed if each true

    Assuming your "names" are just to illustrate, see if this is something you can build on....

    A
    B
    1
    1
    AAA
    2
    1
    BBB
    3
    1
    CCC

    B1=IF(A1=1,"AAA","")
    B2=IF(A1=1,"BBB","")
    B3=IF(A1=1,"CCC","")

    =SUBSTITUTE(TRIM(B1&" "&B2&" "&B3&" "&B4&" "&B5&" "&B6&" "&B7&" "&B8&" "&B9&" "&B10)," ",",")
    (THis method cam from another member here - Martin, I think)
    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 Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: IF with multiple logical tests with text displayed if each true

    if A1 and A2 both contain 1 then I want "London, Paris" displayed in the cell
    They want comma delimiters which makes it much more difficult over a large range of cells.

  5. #5
    Registered User
    Join Date
    03-24-2014
    Location
    London, England
    MS-Off Ver
    Excel 2011
    Posts
    8

    Re: IF with multiple logical tests with text displayed if each true

    More than open to the idea but don't know enough about VBA functions to even know where to start!

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: IF with multiple logical tests with text displayed if each true

    Try this...

    With your file open...

    Press the key combination of Alt+F11 to open the Visual Basic Editor

    Goto the menu Insert > Module

    Copy the VBA code from this post and paste it into the window that opens on the right side of the screen.

    Press the key combination of ALT+Q to close the Visual Basic Editor and return to Excel.

    Let's assume your data looks something like this:

    Data Range
    A
    B
    1
    Header
    Header
    2
    1
    London
    3
    1
    Paris
    4
    Berlin
    5
    Boston
    6
    1
    Pittsburgh
    7
    Madrid
    8
    Rome
    9
    Sydney
    10
    1
    Chicago


    Enter this array formula** in D2:

    =concatall(IF(A2:A10=1,B2:B10,""),", ")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    This will be the result:

    Data Range
    A
    B
    C
    D
    1
    Header
    Header
    ------
    Concatenated
    2
    1
    London
    London, Paris, Pittsburgh, Chicago
    3
    1
    Paris
    4
    Berlin
    5
    Boston
    6
    1
    Pittsburgh
    7
    Madrid
    8
    Rome
    9
    Sydney
    10
    1
    Chicago

  7. #7
    Registered User
    Join Date
    03-24-2014
    Location
    London, England
    MS-Off Ver
    Excel 2011
    Posts
    8

    Re: IF with multiple logical tests with text displayed if each true

    That has worked perfectly Tony, thank you so much! Worrying that I'm sitting up at 2:23am (I'm in London) working on this but I can now sleep easy.

    Thanks again.

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: IF with multiple logical tests with text displayed if each true

    You're welcome. Thanks for the feedback!


    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.

+ 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] Multiple Logical Tests in an IF function
    By scrouse14 in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 07-26-2014, 03:15 PM
  2. [SOLVED] Multiple Logical Tests Required
    By KateMaz in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-28-2013, 10:22 AM
  3. Multiple IF logical tests
    By plauterborn in forum Excel General
    Replies: 3
    Last Post: 02-14-2012, 04:39 PM
  4. 1 Fn, 2 Logical tests, 1 True value, 2 False values
    By ryanchry in forum Excel General
    Replies: 2
    Last Post: 01-03-2012, 04:09 PM
  5. Multiple text Logical tests
    By smanderson in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-21-2010, 04:47 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