# Concatenate Multiple Cells Based on Criteria in Excel (4 Methods)

Sometimes it becomes necessary in excel to concatenate multiple cells based on criteria. This article shows how to do that in 4 different ways. The methods include formulas and excel functions. The following picture gives an idea about the purpose of this article. ## 4 Ways to Concatenate Multiple Cells Based on Criteria in Excel

Here, I am going to illustrate the 4 methods in excel to concatenate multiple cells based on criteria. So, let’s begin!

### 1. Combine Multiple Cells Based on Criteria with Formula & Filter

Assume, you have the following dataset containing colors with codes. You want to concatenate the Color cells based on their codes. 📌Steps

• At first, enter the following formula in cell D5:
`=IF(B6<>B5,C6,D5&","&C6)`
• After that, use the fill handle tool to apply this formula to the cells below. • Next, apply the following formula in cell E5:
`=IF(B6<>B7,CONCAT(B6,",""",D6,""""),"")` • Then, select cell E4. After that, select Sort & Filter >> Filter from the Data tab as shown in the following picture. • After that, the Filter column will look as follows. • Next, click on the drop-down arrow in cell E4. Uncheck the (Blanks) after that. Then, hit the OK. • Finally, the Color cells will be concatenated as follows. Read More: How to Concatenate Multiple Cells With Space in Excel (7 Methods)

### 2. Concatenate Multiple Cells Based on Criteria with CONCAT Function

Alternatively, you can use the CONCAT function in excel to concatenate multiple cells based on criteria. Follow the steps below to be able to do that.

📌Steps

• First, let’s modify the earlier dataset as follows to make the method more easily understandable. • Then, enter the following formula in cell F5:
`=CONCAT(IF(C5:C16=E5,B5:B16,""))` • Now, enter a color name in cell E5. Let’s say, Yellow, for example.
• Then, the result will look as follows. • Now, change the criteria Color name as follows and see how the result changes too. ### 3. Join Multiple Cells Based on Criteria with TEXTJOIN Function

You can also use the TEXTJOIN function in excel to concatenate multiple cells based on criteria. Follow the steps below to learn how to do that.

📌Steps

• First, imagine having a dataset as follows containing students’ marks. • Now, suppose you want the students’ IDs who got more marks than your criteria concatenated in cell F5.
• Then enter the criteria in cell E5. Let’s say, you want to find out who got more than 82 marks among them. • After that, apply the following formula in cell F5.
`=TEXTJOIN(",",TRUE,IF(\$C\$5:\$C\$16>E5,\$B\$5:\$B\$16,""))`
• You will see the IDs concatenated as follows. • You can change the criteria value as well as the criteria in the formula.
• Suppose you want to find out who got less than or equal to 80 marks. Then, change the criteria value to 80 and the formula to the following one.
`=TEXTJOIN(",",TRUE,IF(\$C\$5:\$C\$16<=E5,\$B\$5:\$B\$16,""))` Read More: How to Bold Text in Concatenate Formula in Excel (2 Methods)

### 4. Concatenate Multiple Cells Based on Criteria with UDF

You can also use a User Defined Function (UDF) in excel to concatenate multiple cells based on criteria. Follow the steps below to see how to do that.

📌Steps

• First, consider the following dataset similar to the earlier one. • Then, enter the following formula in cell E5.
`=UNIQUE(C5:C16,FALSE,FALSE)`
• This gives the list of unique marks obtained by the students. • After that, press ALT+F11 to open the Microsoft Visual Basic for Applications. You will also find it in the Developer tab. Then select Insert>>Module. • Next, copy the following code and paste it on the blank module.
``````Function CONCATIF(Criteria As Range, Concatcriteria As Variant, ConcatRange As Range, Optional Delimiter As String = ",") As Variant
Dim Results As String
On Error Resume Next
If Criteria.Count <> ConcatRange.Count Then
CONCATIF = CVErr(xlErrRef)
Exit Function
End If
For j = 1 To Criteria.Count
If Criteria.Cells(j).Value = Concatcriteria Then
Results = Results & Delimiter & ConcatRange.Cells(j).Value
End If
Next j
If Results <> "" Then
Results = VBA.Mid(Results, VBA.Len(Delimiter) + 1)
End If
CONCATIF = Results
Exit Function
End Function`````` • Then, select Close and Return to Microsoft Excel from the File tab. • After that, apply the following formula in cell F5 and drag it to the cells below.
`=CONCATIF(\$C\$5:\$C\$16,E5,\$B\$5:\$B\$16,",")`
• Finally, you will see the result as follows. Read More: Macro to Concatenate Multiple Columns in Excel (with UDF and UserForm)

## Things to Remember

• The CONCATENATE function is an earlier version to the CONCAT function. But, both functions give the same result.
• The TEXTJOIN function may only be available in the newer versions of Microsoft Excel.

## Conclusion

Now, you know the 4 different methods in excel to concatenate multiple cells based on criteria. If you have any further questions or suggestions, please share the comment section below. You may also visit our Exceldemy blog to learn more about excel and improve your performance.

## Related Articles #### Md. Shamim Reza

Hello there! This is Md. Shamim Reza. Working as an Excel & VBA Content Developer at ExcelDemy. We try to find simple & easy solutions to the problems that Excel users face every day. Our goal is to gather knowledge, find innovative solutions through them and make those solutions available for everybody. Stay with us & keep learning.

We will be happy to hear your thoughts 