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 qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.

Subscribe

Subscribe for awesome Microsoft Excel videos 😃

John MacDougall

I’m John, and my goal is to help you Excel!

You’ll find a ton of awesome tips, tricks, tutorials, and templates here to help you save time and effort in your work.

Related Posts

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?

  2. Neeraj

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

    • John

      Use the delimiter ","

  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…?

  4. Robert

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

    • John

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

  5. joaq

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

    • John

      Did you create the formula with Ctrl Shift Enter?

      • 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

        • 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 😂

  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!

Get the Latest Microsoft Excel Tips

Follow Us

Follow us to stay up to date with the latest in Microsoft Excel!

Subscribe for awesome Microsoft Excel videos 😃