If & Concatenate Multiple Fields

catyanne

New Member
Joined
Aug 16, 2018
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
I am trying to concatenate multiple fields if there is data there. G2 is what I want the data to look like, only picking up the cells with data and concatenate with the heading with + between each fields..

I managed to only get one cell and header =IF(A2="No","",CONCATENATE(TEXT(B2,$###K")," ",B1))) but can't figure out how to concatenate the other cells that have data.

ABCDEFGH
1INVESTIGATEType 1 VarType 2 VarType 3 VarType 4 VarType 5 VarComment
2
Yes​
-1​
2-15-$1K Type 1 Var + $2K Type 3 Var + -$15K Type 5 Var
3
Yes​
2-14$2K Type 1 Var + -$1K Type 2 Var + $4K Type 4 Var
4
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Given that you don't have your excel version shown on your profile (please update your Account details ) this may or may not work for you.
Book1
ABCDEFG
1InvestigateType 1 VarType 2 VarType 3 VarType 4 VarType 5 VarComment
2Yes-12-15-$1K Type 1 Var + $2K Type 3 Var + -$15K Type 5 Var
3Yes2-14$2K Type 1 Var + -$1K Type 2 Var + $4K Type 4 Var
Sheet4
Cell Formulas
RangeFormula
G2:G3G2=IF(A2="No","",TEXTJOIN(" + ",1,IF(B2:F2="","",TEXT(B2:F2,"$###K")&" "&$B$1:$F$1)))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Given that you don't have your excel version shown on your profile (please update your Account details ) this may or may not work for you.
Book1
ABCDEFG
1InvestigateType 1 VarType 2 VarType 3 VarType 4 VarType 5 VarComment
2Yes-12-15-$1K Type 1 Var + $2K Type 3 Var + -$15K Type 5 Var
3Yes2-14$2K Type 1 Var + -$1K Type 2 Var + $4K Type 4 Var
Sheet4
Cell Formulas
RangeFormula
G2:G3G2=IF(A2="No","",TEXTJOIN(" + ",1,IF(B2:F2="","",TEXT(B2:F2,"$###K")&" "&$B$1:$F$1)))
Press CTRL+SHIFT+ENTER to enter array formulas.

It's Excel 2016 so Textjoin does not work. Thanks
 
Upvote 0
Hi,

It's not pretty, and took me awhile to put together, my fingers are tired from typing...
But it seems to work:

Book3.xlsx
ABCDEFG
1INVESTIGATEType 1 VarType 2 VarType 3 VarType 4 VarType 5 VarComment
2Yes-12-15-$1K Type 1 Var + $2K Type 3 Var + -$15K Type 5 Var
3Yes2-14$2K Type 1 Var + -$1K Type 2 Var + $4K Type 4 Var
Sheet859
Cell Formulas
RangeFormula
G2:G3G2=TRIM(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(" $"&B2&" b "&" $"&C2&" c "&" $"&D2&" d "&" $"&E2&" e "&" $"&F2&" f ","$ b",""),"$ c",""),"$ d",""),"$ e",""),"$ f","")&"|"," b ","K "&B$1&" + ")," c ","K "&C$1&" + ")," d ","K "&D$1&" + ")," e ","K "&E$1&" + ")," f ","K "&F$1),"$-","-$")),"+ |",""),"|",""))
 
Upvote 0
OOps, got so caught up with joining the text string, forgot to test A column for Yes, corrected below, same formula, just added test for Yes/No:

Book3.xlsx
ABCDEFG
1INVESTIGATEType 1 VarType 2 VarType 3 VarType 4 VarType 5 VarComment
2Yes-12-15-$1K Type 1 Var + $2K Type 3 Var + -$15K Type 5 Var
3Yes2-14$2K Type 1 Var + -$1K Type 2 Var + $4K Type 4 Var
4No12-3 
5Yes4-5$4K Type 2 Var + -$5K Type 3 Var
Sheet859
Cell Formulas
RangeFormula
G2:G5G2=IF(A2="Yes",TRIM(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(" $"&B2&" b "&" $"&C2&" c "&" $"&D2&" d "&" $"&E2&" e "&" $"&F2&" f ","$ b",""),"$ c",""),"$ d",""),"$ e",""),"$ f","")&"|"," b ","K "&B$1&" + ")," c ","K "&C$1&" + ")," d ","K "&D$1&" + ")," e ","K "&E$1&" + ")," f ","K "&F$1),"$-","-$")),"+ |",""),"|","")),"")
 
Upvote 0
OOps, got so caught up with joining the text string, forgot to test A column for Yes, corrected below, same formula, just added test for Yes/No:

Book3.xlsx
ABCDEFG
1INVESTIGATEType 1 VarType 2 VarType 3 VarType 4 VarType 5 VarComment
2Yes-12-15-$1K Type 1 Var + $2K Type 3 Var + -$15K Type 5 Var
3Yes2-14$2K Type 1 Var + -$1K Type 2 Var + $4K Type 4 Var
4No12-3 
5Yes4-5$4K Type 2 Var + -$5K Type 3 Var
Sheet859
Cell Formulas
RangeFormula
G2:G5G2=IF(A2="Yes",TRIM(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(" $"&B2&" b "&" $"&C2&" c "&" $"&D2&" d "&" $"&E2&" e "&" $"&F2&" f ","$ b",""),"$ c",""),"$ d",""),"$ e",""),"$ f","")&"|"," b ","K "&B$1&" + ")," c ","K "&C$1&" + ")," d ","K "&D$1&" + ")," e ","K "&E$1&" + ")," f ","K "&F$1),"$-","-$")),"+ |",""),"|","")),"")
This works perfectly. Thank you. If I was to add an extra column of data. I have 8 columns of data eg B-I. Am I able to add the other columns after the highlighted?

1616640866811.png
 
Upvote 0
Here's a relatively shorter version of my formula, when I was testing the TEXT function for my original formula, for some reason it didn't work, it turned out there were hidden characters when I copied your OP data, anyway, I think this is much "cleaner"

As for your question regarding 3 more columns, Yes, you can just add on to the formula, you'll also need 3 additional SUBSTITUTE functions, let me know if you need help with that:

Book3.xlsx
ABCDEFG
1INVESTIGATEType 1 VarType 2 VarType 3 VarType 4 VarType 5 VarComment
2Yes-12-15-$1K Type 1 Var + $2K Type 3 Var + -$15K Type 5 Var
3Yes2-14$2K Type 1 Var + -$1K Type 2 Var + $4K Type 4 Var
4No12-3 
5Yes4-5$4K Type 2 Var + -$5K Type 3 Var
Sheet864
Cell Formulas
RangeFormula
G2:G5G2=IF(A2="Yes",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(B2,"$0K ")&B$1&TEXT(C2,"$0K ")&C$1&TEXT(D2,"$0K ")&D$1&TEXT(E2,"$0K ")&E$1&TEXT(F2,"$0K ")&F$1,"$0K "&B$1,""),"$0K "&C$1,""),"$0K "&D$1,""),"$0K "&E$1,""),"$0K "&F$1,"")&"|","Var","Var + "),"+ |",""),"")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,194
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top