How To Conditionally Concatenate A Range

2018-01-06

How-To-Conditionally-Concatenate-A-Range How To Conditionally Concatenate A Range

Example

{=TEXTJOIN("",TRUE,IF($C$3:$C$11=E3,$B$3:$B$11,""))}

Generic Formula

{=TEXTJOIN(Delimiter,TRUE,IF(ConditionRange=Condition,Range,""))}

Note: This is an array formula. Do not type out the {} brackets. Hold Ctrl + Shift then press Enter while in Edit Mode to create an array formula. For Mac, use + Shift + Return.
  • Range – This is range of values which we want to concatenate together.
  • Delimiter – This is the delimiter value which we want to use to separate values by in our concatenation. Use empty quotes if we don’t want to use a delimiter.
  • ConditionRange – This is the range of values which we will use to test whether or not to concatenate an item from our Range.
  • Condition – This is the condition to test.

What It Does

This formula will conditionally concatenate a range based on a criteria in another range.

How It Works

IF(ConditionRange=Condition,Range,””) will create an array containing data from the Range when it meets the given condition. In our example this will create the following array.

{"";"E";"X";"";"C";"";"E";"L";""}

TEXTJOIN(Delimiter,TRUE,Array) will concatenate the individual items in the Array and separating them with the chosen Delimiter. Using TRUE as the middle argument will skip any blank cells in the array. In our example TEXTJOIN(“”,TRUE,{“”;”E”;”X”;””;”C”;””;”E”;”L”;””}) results in EXCEL!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Subscribe

Advertisement

Related Articles

Comments

11 Comments

  1. Sally T

    Hi John, This solves a similar problem I’m trying to solve in my own excel spreadsheet. I am not familiar with array formula. Can you expand on you How To Conditionally Concatenate A Range instructions for those who are new to array formulas?

    Reply
  2. Neeraj

    Need to put commas as well in the output.
    Kindly help. 🙂

    Reply
    • John

      Use the delimiter ","

      Reply
  3. lm

    I have this a shot, but got a “name” error code. I tried downloading your example file and it also had the same error…?

    Reply
  4. Robert

    I tried this where the range and condition is over 100k records and receiving a #VALUE! results.

    Reply
    • John

      Not 100% sure, but it might be because a cell can only contain 32k characters.

      Reply
  5. joaq

    it doesn’t work at all, not even your exact example. I wonder why

    Reply
    • John

      Did you create the formula with Ctrl Shift Enter?

      Reply
      • joaq

        It works now!!! I mean MY MISTAKE! (yep, I missed that detail) that was it! Y
        ou are my new hero! Thanks Sir. you really saved me from a lot of work and using VBA didn’t make sense

        Reply
        • John

          Yes, there are usually many ways to do something in Excel, just depends on the situation which is best.

          Glad I could be a “hero” today 😂

          Reply
  6. Matthew Cordell

    Brilliant! I was not familiar with array formulas. (I also excitedly rushed in without reading the ctrl+shift+enter instruction).
    Eventually I got this working just as I wanted.
    Thanks!

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get The Latest News

Follow Us

Follow us on social media to stay up to date with the latest tips in Excel!

Pin It on Pinterest

Share This