ListFerret mascot

Home › Guides › Column to Comma Separated List (Excel, Sheets)

Column to Comma Separated List: How to Convert in Excel, Google Sheets, SQL and Online

You have a column of values (IDs, names, email addresses) and you need them as one line separated by commas: for a database query, a form field, a spreadsheet function or the “To” box of an email. Or you have the opposite problem, a long comma delimited list that needs to become a column. This guide covers every common way to do both, the formulas that work in each spreadsheet, and the quoting problems that quietly break the result.

The quick answer

The rest of the guide explains when each one is the right choice and what to watch for.

Going the other way? See how to turn a comma separated list into a column, or how to convert a list to CSV when the file has to be imported somewhere.

Convert a column to a comma separated list online

If your data is in an email, a document, a web page or a text file, you do not need a spreadsheet at all. Copy the column, paste it into the converter, and the comma separated list appears as you type. In this example the column has five names, one of them repeated. With “Remove duplicates” on, a comma as the separator and single quotes around each item, five rows become one line ready to paste into a query:

The List Converter tool turning a column of five names into the single line 'Ava','Ben','Cleo','Dev' with the duplicate removed
Example: five rows in, four items out (the duplicate “Ben” removed). The sample names are made up for illustration.

Beyond the basic join, the converter can trim stray spaces, drop blank rows, change case, add a prefix or suffix to every item, wrap the whole list in ( ) or [ ], escape quotes that appear inside values, and split a very long list into groups of a fixed size. Each of those exists because of a specific problem covered below.

In Excel: TEXTJOIN and the older alternatives

With your values in A2:A100, this formula joins them with a comma and a space and skips empty cells:

=TEXTJOIN(", ", TRUE, A2:A100)

The first argument is the separator, the second tells Excel to ignore blanks, and the third is the range. TEXTJOIN exists in Excel 2019, Excel 2021 and Microsoft 365. If you have an older version, use one of these instead:

SituationWhat to do
Excel 2016 or earlier, a few dozen rowsIn column B enter =A2&"," and fill down, copy column B, paste it into a text editor and delete the line breaks
Any version, no formulasPaste the column into Notepad++, open Find and Replace in Extended mode, and replace \r\n with ,
Large or repeating jobPower Query: load the column, add a Group By, and combine the values with a custom delimiter

To put quotes around each value, which you need for text in SQL, JSON and most programming languages, do the quoting inside the formula:

=TEXTJOIN(",", TRUE, "'" & A2:A100 & "'")

In Microsoft 365 this just works. In Excel 2019 it must be confirmed as an array formula with Ctrl+Shift+Enter, otherwise it returns only the first item.

In Google Sheets: TEXTJOIN, JOIN and ARRAYFORMULA

TEXTJOIN behaves the same way in Sheets as in Excel:

=TEXTJOIN(", ", TRUE, A2:A100)

Sheets also has JOIN, which does not have an option to ignore blanks. To get the same result with it, filter the blanks out first:

=JOIN(", ", FILTER(A2:A100, A2:A100<>""))

To add quotes, the concatenation has to be evaluated across the range, which in Sheets means wrapping it in ARRAYFORMULA:

=ARRAYFORMULA(TEXTJOIN(",", TRUE, "'" & A2:A100 & "'"))

If the range contains empty cells this will produce empty quoted items (''), so use a range that matches your data or filter blanks as above.

Convert a comma separated list to a column

Converting a comma delimited list back to rows (sometimes searched as “comma to column”) is the same job in reverse.

ToolMethod
Google Sheets=TRANSPOSE(SPLIT(A1, ",")). Note that SPLIT treats each character of the delimiter separately by default, so for ", " add a third argument: SPLIT(A1, ", ", FALSE)
Excel 365=TEXTSPLIT(A1, , ",") returns the values down a column. Wrap it in TRIM() to remove spaces after the commas
Older ExcelData, then Text to Columns, choose Delimited and Comma. Then copy the row and use Paste Special, then Transpose, to turn it into a column
OnlineSet the converter’s input separator to Comma and the output separator to New line. Choose “Auto” to split on commas, semicolons, tabs and line breaks together

Comma delimited list versus a CSV file

People searching for “column to CSV” or “list to CSV” are usually after one of two things, and they are not the same:

The difference matters because real CSV has rules. A field containing a comma, a double quote or a line break must be wrapped in double quotes, and a double quote inside a field is written as two double quotes (this is the convention formalised in RFC 4180). A naive join of the values Smith, John and Lee produces Smith, John,Lee, which a CSV reader sees as three fields instead of two. If your values might contain commas, wrap each item in double quotes and escape any quotes inside them, or use a different separator such as a pipe or a tab.

Quotes inside values: the bug that breaks queries

Wrapping items in quotes is easy until a value contains the quote character. Take the name O’Brien wrapped in single quotes for SQL: 'O'Brien' is invalid, because the apostrophe ends the string early. There are two standard fixes, and which one is right depends on where the list is going:

DestinationEscape ruleO’Brien becomes
SQL string literal, CSVDouble the quote character'O''Brien'
JSON, JavaScript, Python, most codePut a backslash before the quote (and before any backslash)'O\'Brien'

Does the doubled quote really work? Yes. Inside a quoted SQL string, two single quotes in a row are read as one literal apostrophe, not as the end of one string and the start of another. It is standard SQL and works in PostgreSQL, SQL Server, Oracle, MySQL and SQLite. You can check on your own database with SELECT 'O''Brien';, which returns O'Brien. The backslash form (') works in MySQL by default but not in standard-conforming databases such as PostgreSQL, so doubling the quote is the portable choice for SQL.

The List Converter’s Escape quotes inside items option applies either rule for you. Using the same five names with “O’Brien” added, single quotes, a comma separator and the whole list wrapped in parentheses, the SQL-style output is:

('Ava','O''Brien','Cleo','Dev','Eli','Ben')

Building an SQL IN list

A comma separated list inside parentheses is exactly what the IN operator wants:

SELECT *
FROM customers
WHERE name IN ('Ava','O''Brien','Cleo','Dev','Eli','Ben');

Three practical points:

For application code, use parameters. Building SQL by pasting values into a string is fine for a one-off query you run yourself. If values come from users or from another system, use parameterised queries instead, because hand-built strings are how SQL injection happens.

Arrays for code: Python, JavaScript and JSON

The same technique produces list literals. Wrap each item in double quotes, join with commas, and wrap the whole list in square brackets:

["Ava","Ben","Cleo","Dev"]

That line is valid JSON, valid JavaScript and a valid Python list. JSON requires double quotes, so choose double quotes and the backslash escape option if any value contains a quote or a backslash.

Pasting a list into an email

Gmail accepts a comma separated list of addresses in the To, Cc or Bcc field. Outlook traditionally expects semicolons between addresses, although classic Outlook has a setting that also allows commas. If a pasted list is rejected, switch the converter’s separator to Semicolon. Providers also cap the number of recipients per message, so for a big list send in batches. Using Bcc and checking you have the right to email the people on it are your responsibility.

Common problems and how to fix them

SymptomLikely causeFix
Items have a stray space at the start, so lookups failSpaces after the commas, or trailing spaces in cellsTurn on trimming, or use TRIM() in the spreadsheet
A comma at the end of the listBuilt by hand or by a formula that adds a comma after every itemJoin with TEXTJOIN or the converter, which only put separators between items
Leading zeros disappear (ZIP codes, IDs)Excel stored the values as numbersFormat the column as Text before pasting the data in
Empty items such as ,,Blank rows in the columnUse the “ignore blanks” option (TRUE in TEXTJOIN) or “Remove empty items”
Everything is on one row but you expected a columnValues were separated by line breaks inside a single cellSet the input separator to New line in the converter
A name with a comma splits into twoA comma inside a value in a comma separated listQuote the values, or use a pipe or tab separator

Frequently asked questions

How do I convert a column to a comma separated list without Excel?

Paste the column into an online converter such as the List Converter, pick comma as the output separator, and copy the result. It also removes blank rows and duplicates if you want.

What is the Excel formula to turn a column into a comma separated list?

Use =TEXTJOIN(", ", TRUE, A2:A100) in Excel 2019 or later and in Microsoft 365. In older versions, build the list with a helper column or use Find and Replace in a text editor.

How do I convert a comma separated list to a column?

In Google Sheets use =TRANSPOSE(SPLIT(A1, ",")). In Excel 365 use =TEXTSPLIT(A1, , ","). Online, set the input separator to Comma and the output separator to New line.

How do I put quotes around each item in the list?

Wrap each item while joining, for example =TEXTJOIN(",", TRUE, "'" & A2:A100 & "'"), or tick the quote option in the List Converter. If values can contain the quote character, also enable quote escaping.

How many values can I put in an SQL IN list?

It depends on the database. Oracle has historically limited a list to 1,000 expressions, and SQL Server limits a request to 2,100 parameters. Split long lists into groups to stay under the limit.

Is a comma delimited list the same as a CSV file?

Not quite. A comma delimited list is a single line of values separated by commas. A CSV file is a text file of rows and fields that follows quoting rules for values containing commas, quotes or line breaks.

Try it now: use the free List Converter - private, instant and runs in your browser. Open List Converter →

More guides

Share this page: XFacebookLinkedInRedditEmail