Written by Allen Wyatt (last updated May 9, 2026)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365
Harrison knows that he can save a worksheet as a CSV file. However, he only needs to convert the range C2:J51 into a CSV. He wonders if there is an easy way to do this.
There are several ways you can do this. A simple way is to open both the source workbook and a brand-new workbook. Copy the C2:J51 range and paste it into the new workbook. (You can use Paste Values to paste the information.) Then you can save the new workbook in CSV format. (Harrison said he knows how to do this.)
Another approach is to open the source workbook and a new Notepad document. In the workbook, enter the following formula into cell L2:
=TEXTJOIN(",",FALSE,C2:J2)
Copy this down to the range L3:L51, and you end up with strings of comma-separated values. Select the range L2:L51, copy it, and paste it within the Notepad document. Save it using a filename extension of CSV, and you have your desired CSV file.
There is one potential gotcha to this—if your source information includes cells that contain commas. In that case, you'll want to modify the formula so that it adds quote marks around the cell contents:
=CHAR(34)&TEXTJOIN(CHAR(34)&","&CHAR(34),FALSE,C2:J2)&CHAR(34)
If you need to do this sort of thing routinely, then you could benefit by using a macro to do the conversion and saving. Here's one that is rather robust:
Sub ExportRangeToCSV()
Dim row As Range
Dim cell As Range
Dim line As String
Dim output As String
Dim f As Integer
Dim s As String
Dim sFile As Variant
If TypeName(Selection) <> "Range" Then
MsgBox "Please select a worksheet range first."
Exit Sub
End If
For Each row In Selection.Rows
line = ""
For Each cell In row.Cells
s = cell.Text ' Change to .Value if underlying value is wanted
If InStr(s, """") > 0 Then
s = Replace(s, """", """""")
End If
If InStr(s, ",") > 0 Or InStr(s, """") > 0 Or _
InStr(s, vbCr) > 0 Or InStr(s, vbLf) > 0 Then
s = """" & s & """"
End If
line = line & s & ","
Next cell
If Len(line) > 0 Then
line = Left(line, Len(line) - 1)
output = output & line & vbCrLf
End If
Next row
sFile = Application.GetSaveAsFilename( _
InitialFileName:="export.csv", _
FileFilter:="CSV Files (*.csv), *.csv")
If sFile <> False Then
f = FreeFile
Open CStr(sFile) For Output As #f
Print #f, output;
Close #f
MsgBox "CSV File Saved"
Else
MsgBox "File Not Saved"
End If
End Sub
The macro assumes that you are selecting the cells you want to output in a CSV file. It correctly handles special characters within a cell, such as commas, tabs, newlines, and quote marks. It also allows the user to specify a filename and location for the file.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13982) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365.
Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!
When you import a CSV file into an Excel worksheet, you may be surprised at how the program allocates the information ...
Discover MoreIf you don't like the way that Excel exports information you intend to use with other programs, then your best bet is to ...
Discover MoreWhen you choose to save worksheet data in CSV format, Excel gives you three choices for file formats. Those choices are ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2026-05-15 16:12:56
J. Woolley
Assuming Harrison has Copilot activated in Excel (currently requires Excel 365), here's another way he can "convert the range C2:J51 into a CSV."
First open the worksheet, then click the Copilot icon and request this:
"Convert the range C2:J51 to CSV."
Copilot will eventually reply with this:
"Here is the CSV output for range C2:J51:" followed by a text box containing the CSV.
Select the CSV in the text box and copy it to the clipboard (Ctrl+C), then paste it wherever it is needed (Ctrl+V).
2026-05-12 11:32:49
J. Woolley
Here's an alternate version of the Tip's macro based on its first suggestion:
"A simple way is to open both the source workbook and a brand-new workbook. Copy the C2:J51 range and paste it into the new workbook. (You can use Paste Values to paste the information.) Then you can save the new workbook in CSV format." In this case Excel automatically quotes text having special characters like comma, CR/LF, leading/trailing spaces, and quotation marks (which are doubled).
Sub ExportRangeToCSV2()
Const myName = "ExportRangeToCSV2"
Dim var As Variant, msg As String, rng As Range
var = Selection.Address
msg = "Select a contiguous range of cells for export to a CSV file:"
On Error Resume Next
Set rng = Application.InputBox(msg, myName, var, Type:=8)
On Error GoTo 0
If rng Is Nothing Then Exit Sub 'user clicked Cancel
rng.Select
If rng.Areas.Count > 1 Then
MsgBox "Selected range is invalid", vbCritical, myName
Exit Sub
End If
rng.Copy
Workbooks.Add xlWBATWorksheet 'new ActiveWorkbook/ActiveSheet
Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
var = Application.GetSaveAsFilename(myName, _
"Comma Separated Values (*.csv), *.csv")
If var = False Then 'user clicked Cancel
ActiveWorkbook.Close False
Exit Sub
End If
On Error Resume Next
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs var, xlCSV
ActiveWorkbook.Close False
Application.DisplayAlerts = True
If Err = 0 Then
msg = "Exported comma separated values from " _
& rng.Address & " to" & vbLf & var & vbLf & vbLf _
& "Do you want to open that file in Notepad?"
If MsgBox(msg, vbYesNo, myName) = vbYes Then _
Shell "Notepad.exe " & var, vbNormalFocus
End If
On Error GoTo 0
End Sub
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2026 Sharon Parq Associates, Inc.
Comments