How do I save a CSV file in Excel on a PC?

After I do that, I already have the formula to text to column based on each record types fixed column width counts.

Every ID will have RecordType1 and can have additional rows of RecordType2 and RecordType3. Pretend there are 500 Unique IDs (recordtype1), 900 Records total (400additional rows of data for RecordType2 & 3)

Example:
HeaderRecord DateDateHourDate L
RecordType1 First Last ID01 TitleDate1Date2 zerofilldate3
RecordType2 ID01 Date1Date2 YesNo Spacefill
RecordType3 ID01 DataInfoDate1 ZerofillDate
RecordType1 First Last ID02 TitleDate1Date2 zerofilldate3
RecordType2 ID02 Date1Date2 YesNo Spacefill
RecordType3 ID01 DataInfoDate1 ZerofillDate
RecordType1 First Last ID03 TitleDate1Date2 zerofilldate3
RecordType2 ID03 Date1Date2 YesNo Spacefill
RecordType3 ID03 DataInfoDate1 ZerofillDate
TrailerRecord Count

Reply
Note:  After you change the list separator character for your computer, all programs use the new character as a list separator. You can change the character back to the default character by following the same procedure.

Woah!  It should show all your data to you.  If you followed the instructions correctly (and assuming that I typed them in correctly), R should now have your data associated with the word MyData.  Now, you can progress to performing analyses with your data in R.  As always, if you have any questions, comments, or concerns, please email me a [email protected].

For those situations where you need a bit more customisation of the output (separator or decimal symbol), or who have large dataset (over 65k rows), I wrote the following:

Option Explicit

Sub rng2csv(rng As Range, fileName As String, Optional sep As String = ";", Optional decimalSign As String)
'export range data to a CSV file, allowing to chose the separator and decimal symbol
'can export using rng number formatting!
'by Patrick Honorez --- www.idevlop.com
    Dim f As Integer, i As Long, c As Long, r
    Dim ar, rowAr, sOut As String
    Dim replaceDecimal As Boolean, oldDec As String

    Dim a As Application:   Set a = Application

    ar = rng
    f = FreeFile()
    Open fileName For Output As #f

    oldDec = Format(0, ".")     'current client's decimal symbol
    replaceDecimal = (decimalSign <> "") And (decimalSign <> oldDec)

    For Each r In rng.Rows
        rowAr = a.Transpose(a.Transpose(r.Value))
        If replaceDecimal Then
            For c = 1 To UBound(rowAr)
                'use isnumber() to avoid cells with numbers formatted as strings
                If a.IsNumber(rowAr(c)) Then
                    'uncomment the next 3 lines to export numbers using source number formatting
'                    If r.cells(1, c).NumberFormat <> "General" Then
'                        rowAr(c) = Format$(rowAr(c), r.cells(1, c).NumberFormat)
'                    End If
                    rowAr(c) = Replace(rowAr(c), oldDec, decimalSign, 1, 1)
                End If
            Next c
        End If
        sOut = Join(rowAr, sep)
        Print #f, sOut
    Next r
    Close #f

End Sub

Sub export()
    Debug.Print Now, "Start export"
    rng2csv shOutput.Range("a1").CurrentRegion, RemoveExt(ThisWorkbook.FullName) & ".csv", ";", "."
    Debug.Print Now, "Export done"
End Sub

After I do that, I already have the formula to text to column based on each record types fixed column width counts.

Every ID will have RecordType1 and can have additional rows of RecordType2 and RecordType3. Pretend there are 500 Unique IDs (recordtype1), 900 Records total (400additional rows of data for RecordType2 & 3)

Example:
HeaderRecord DateDateHourDate L
RecordType1 First Last ID01 TitleDate1Date2 zerofilldate3
RecordType2 ID01 Date1Date2 YesNo Spacefill
RecordType3 ID01 DataInfoDate1 ZerofillDate
RecordType1 First Last ID02 TitleDate1Date2 zerofilldate3
RecordType2 ID02 Date1Date2 YesNo Spacefill
RecordType3 ID01 DataInfoDate1 ZerofillDate
RecordType1 First Last ID03 TitleDate1Date2 zerofilldate3
RecordType2 ID03 Date1Date2 YesNo Spacefill
RecordType3 ID03 DataInfoDate1 ZerofillDate
TrailerRecord Count

Reply

If you spend any time with spreadsheet applications like Microsoft Excel or Google Sheets — or even import certain kinds of data into Microsoft Outlook — you will inevitably encounter a comma-separated values file, commonly known as a CSV.

A CSV file is a simple text file that you can open in a wide variety of programs, including any program that works with plain text like the Notepad app.

What makes a CSV file unique is the way its content is organized. Here's what you need to know about CSV files and how to use them. 

What is a CSV file used for?

A CSV file, as the name implies, typically separates information using commas. It's a way to exchange structured information, like the contents of a spreadsheet, among programs that can't necessarily talk to one another directly.

As long as two programs can both open a CSV file, they can exchange data. For example, you can save contact information from Microsoft Excel as a CSV file, and import it into the address book in Microsoft Outlook.

A typical CSV file looks like this, where each line contains the same sequence of data so any program which needs to read it knows what to expect:

Product, Size, Color, Price

Shirt, Medium, Blue, $14

Shirt, Large, Red, $15

Pants, Medium, Khaki, $23

Despite the name, a CSV doesn't need to rely on commas as the separator between pieces of information. This separator, called a delimiter, can be a semicolon, space, or some other character, though the comma is most common. 

Quick tip: Excel files can only be opened by Excel or Google Sheets whereas CSV files can be opened by any text editing program, such as Notepad or TextEdit.

How to open a CSV file in Microsoft Excel

1. In Excel's ribbon, click the File tab and then click Open.

2. Click Browse and, in the File Explorer box, click the drop-down menu to the right of the File name field. It usually defaults to All Excel Files — change it to All Files.

3. Navigate to the location where the CSV file is stored and select it.

Screenshot of Microsoft Excel file open prompt with a CSV file highlighted.

You might need to change the file type to "All Files" to see the CSV in Excel.Dave Johnson/Insider

4. Follow the Text Import Wizard to open the CSV. Usually, you'll want to select the option to import delimited data (this would be the comma or other separator) and click Next.

5. Choose the kind of delimiter the file is using. You'll know you've selected the correct delimiter when the preview appears structured and organized properly. Click Next.

Microsoft Excel text import wizard with options highlighted.

When you choose the correct delimiter, you should see all the data organized properly in the preview.Dave Johnson/Insider

6. If needed, you can click a column and change the kind of formatting for that data. When you're satisfied, click Finished.

Quick tip: A CSV file is not an Excel file. While CSV files are not standardized and must save images in plaintext (meaning it is impossible to store pictures), Excel files are binaries that are able to contain pictures and rich formatting.

How to open a CSV file in Google Sheets

1. In Google Sheets, click File and then click Open.

2. Find the CSV file and select it. If needed, click Upload and then drag and drop it from your computer.

The Google Sheets upload page.

You might need to upload the CSV file first.Kyle Wilson/Insider

3. The CSV will automatically be formatted properly and appear in Sheets.

How to open a CSV file in a text editor

Unlike spreadsheets, a text editor won't automatically format or structure the CSV file for you. Instead, you'll simply see the data separated by the comma or other delimiter. It's usually not aesthetically appealing, but it's an easy way to see the content of the file. 

1. Open a text editor like Windows Notepad or TextEdit.

2. Click File and then Open.

3. In the "File Open" dialog box, select the CSV file. Depending on the editor, you may need to click a drop-down menu to the right of the "File name" field. If it's currently set to "Text Documents," change it to "All Files."

The Windows Notepad open window with the All Files option highlighted.

You might need to change the file type dropdown to "All Files".Kyle Wilson/Insider

4. Find the CSV file and select it.

How to create a CSV file

You can create CSV files in a few different ways. 

From an Excel spreadsheet

1. Open your Excel document and click on the File tab. In the menu that appears, select Save As.

2. Change the File Format to either Text (Tab delimited) or CSV (Comma delimited).

The Excel export format choices with the CSV option highlighted.

Set the File Format to CSV.Kyle Wilson/Insider

3. Navigate to the location where you wish to save the file, give it a name, and click Save.

Quick tip: Two dialog boxes will appear after step 3. Click OK on the first one and Yes on the second box in order to save the new file. Only one worksheet will be exported at a time. In order to export more than one, repeat the steps for each sheet.

From a Google Sheet

1. Open the Google Sheet that you wish to export.

2. Click File, then Download, and click Comma Separated Values (.csv).

The CSV download option.

Click on Comma Separated Values (.csv)Kyle Wilson/Insider

In a text editor

1. Create a new text file using a text editor, such as Notepad on Windows or TextEdit on macOS.

2. Enter the data that you want the document to contain, separating each value with a comma and each row with a new line.

Data that might be found in a CSV file.

Enclose any commas meant to be in your data with quotation marks to preserve them.Kyle Wilson/Insider

3. Save the file with the extension .csv.

The Notepad file save prompt.

Be sure to set the "Save as type" to "All Files".Kyle Wilson/Insider

Quick tip: If your data itself includes commas, you can protect it by surrounding that entry with quotation marks.

Dave Johnson

Freelance Writer

Dave Johnson is a technology journalist who writes about consumer tech and how the industry is transforming the speculative world of science fiction into modern-day real life. Dave grew up in New Jersey before entering the Air Force to operate satellites, teach space operations, and do space launch planning. He then spent eight years as a content lead on the Windows team at Microsoft. As a photographer, Dave has photographed wolves in their natural environment; he's also a scuba instructor and co-host of several podcasts. Dave is the author of more than two dozen books and has contributed to many sites and publications including CNET, Forbes, PC World, How To Geek, and Insider.

How do I save a CSV file as Excel?

Steps to convert content from a TXT or CSV file into Excel.
Open the Excel spreadsheet where you want to save the data and click the Data tab..
In the Get External Data group, click From Text..
Select the TXT or CSV file you want to convert and click Import..
Select "Delimited". ... .
Click Next..

How do I save a CSV file to desktop?

CSV files, do the following:.
Open a . CSV document in Microsoft Excel..
Click File..
Select Save As....
Select File Type as CSV UTF-8 (Comma delimited) (. csv)..
Click Save..
If prompted, choose Keep Current Format..

How do I open a CSV file in Excel on a PC?

Go to File > Open and browse to the location that contains the text file..
Select Text Files in the file type dropdown list in the Open dialog box..
Locate and double-click the text file that you want to open. If the file is a text file (. txt), Excel starts the Import Text Wizard..

Why I Cannot save CSV file in Excel?

If you still encounter issues while saving your CSV file, try updating Microsoft Excel to the latest version possible. This should patch bugs and glitches in the app and ensure that you have a working version of Excel. Check out the guide below to update Excel: First, open Microsoft Excel and access the File tab.