Make a comma-separated list with quotes for a SQL query
="'"&TEXTJOIN("','",TRUE,A2:A6)&"'"Excel · result on the sample sheet: 'C-1042','C-1057','C-2290','C-1501','C-7731'
Describe what you need and get a working TEXTJOIN formula for Excel and Google Sheets, tested on real data before you copy it. TEXTJOIN joins a list of values with the same delimiter between each one, and can skip blanks.
Each formula below was calculated on its own sample sheet. Open one to see the sheet, why it works, and to try it yourself.
="'"&TEXTJOIN("','",TRUE,A2:A6)&"'"Excel · result on the sample sheet: 'C-1042','C-1057','C-2290','C-1501','C-7731'
=A2&" "&B2Excel · result on the sample sheet: 5 rows (C2:C6)
=TEXTJOIN(", ",TRUE,A2:E2)Excel · result on the sample sheet: 5 rows (F2:F6)
=TEXTJOIN("; ",TRUE,B2:B8)Google Sheets · result on the sample sheet: ana@ruiz.example; raj@patel.example; kim@ortiz.example; mo@diaz.example; sam@cole.example; eve@lund.example
=TEXTJOIN(", ",TRUE,FILTER(B2:B8,A2:A8=E1))Excel · result on the sample sheet: Aiko, Chidi, Fay
=TEXTJOIN(", ",TRUE,IF(B2:F2="X",B$1:F$1,""))Excel · result on the sample sheet: 5 rows (G2:G6)
=SUBSTITUTE(A2,CHAR(10),", ")Excel · result on the sample sheet: 5 rows (B2:B6)
=FILTER(A2:A8,B2:B8=MAX(B2:B8))Excel · result on the sample sheet: 3 rows (D2:D4)
You describe the task in plain English, and it writes the formula, using TEXTJOIN where that's the right tool, for your table or a sample one. The formula is run in our engine in Excel and Google Sheets mode before you see it, so you get its result, not just a guess.
TEXTJOIN joins a list of values with the same delimiter between each one, and can skip blanks.
Yes. Each example below opens a page where you try the formula in a live grid and it's checked as you go, and the TEXTJOIN function page has a practice exercise.