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.
Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!
If you get errors in Excel that your filenames are too long, it can be confusing and frustrating. Applying the ideas ...
Discover MoreWhen you import a CSV file into an Excel worksheet, you may be surprised at how the program allocates the information ...
Discover MoreExcel tries to make sense out of any data that you import from a non-Excel file. Sometimes this can have unwanted ...
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."nFirst open the worksheet, then click the Copilot icon and request this: n"Convert the range C2:J51 to CSV." nCopilot will eventually reply with this: n"Here is the CSV output for range C2:J51:" followed by a text box containing the CSV.nSelect 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: n"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).nnSub ExportRangeToCSV2()n    Const myName = "ExportRangeToCSV2"n    Dim var As Variant, msg As String, rng As Rangen    var = Selection.Addressn    msg = "Select a contiguous range of cells for export to a CSV file:"n    On Error Resume Nextn        Set rng = Application.InputBox(msg, myName, var, Type:=8)n    On Error GoTo 0n    If rng Is Nothing Then Exit Sub 'user clicked Canceln    rng.Selectn    If rng.Areas.Count > 1 Thenn        MsgBox "Selected range is invalid", vbCritical, myNamen        Exit Subn    End Ifn    rng.Copyn    Workbooks.Add xlWBATWorksheet 'new ActiveWorkbook/ActiveSheetn    Range("A1").PasteSpecial xlPasteValuesAndNumberFormatsn    Application.CutCopyMode = Falsen    var = Application.GetSaveAsFilename(myName, _n        "Comma Separated Values (*.csv), *.csv")n    If var = False Then 'user clicked Canceln        ActiveWorkbook.Close Falsen        Exit Subn    End Ifn    On Error Resume Nextn        Application.DisplayAlerts = Falsen        ActiveWorkbook.SaveAs var, xlCSVn        ActiveWorkbook.Close Falsen        Application.DisplayAlerts = Truen        If Err = 0 Thenn            msg = "Exported comma separated values from " _n            & rng.Address & " to" & vbLf & var & vbLf & vbLf _n            & "Do you want to open that file in Notepad?"n            If MsgBox(msg, vbYesNo, myName) = vbYes Then _n                Shell "Notepad.exe " & var, vbNormalFocusn        End Ifn    On Error GoTo 0nEnd 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