Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Correctly Saving Delimited Files.

Correctly Saving Delimited Files

by Allen Wyatt
(last updated May 2, 2015)

3

Raymond indicated that he was having some problems properly exporting delimited files from within Excel. Raymond was requesting that Excel create a file using the tab character as a delimiter. It seems that Excel would not reliably add a tab character at the end of a row when the last field in the row was empty.

Actually, this is how Excel is designed to operate. When exporting information to a delimited file, each row in the data table is handled independently. If one particular row has fewer fields than other rows, Excel doesn't "pad out" the exported row with "blank" fields. This can, of course, lead to problems with some other programs that use the Excel-created file and rely on a static number of fields in each input row.

A workaround for this potential problem is to simply make sure that Excel always has something in every cell of the final column of your data table. This is actually easier than it sounds—all you need to do is make sure the right-most column contains some unique text string, perhaps something like [{|}]. (It is unlikely that such a string would be used elsewhere in your data.) When you export to a delimited file, Excel will always export the same number of fields per row, right up to the unique text string. Then, when you import the delimited file into your other program, you can instruct it to ignore the last field of each row that it imports.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10564) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Correctly Saving Delimited Files.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Adding Hyperlinks

Adding a hyperlink to s text selection is easy to do in Word. All you need to do is make a couple of clicks and specify ...

Discover More

Printing Odd or Even Pages

When you print a worksheet, Excel normally prints all the pages or a consecutive series of pages that you specify. If you ...

Discover More

Making a Drop-Down List Indicator Visible

Data validation allows you to create drop-down lists that aid data entry. If you want the indicator for the drop-down ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Creating a Dated Backup File

As you are developing your workbooks, you might want a way to automatically create backup files that include a date and ...

Discover More

Aligning Cells when Importing from CSV

When you import information from a CSV text file, Excel formats the data according to its default settings. Wouldn't it ...

Discover More

Saving a Workbook with a Preview

When you save your workbooks, Excel can also save a preview image (thumbnail) that can be displayed in the Open dialog ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 8?

2016-03-14 14:12:34

Scott Renz

Thanks, Peter, but I need those characters to be there or an FDA inspector will fail us for not having the exact characters as the original.


2016-03-11 11:37:58

Peter Atherton

Scott

Try running one of these routines to clean the data before running Allen's


Sub CleanReturns()
Dim c As Range

For Each c In Selection
c = WorksheetFunction.Substitute(c, Chr(10), " ")
Next c

End Sub
Sub CleanNPC()
Dim c As Range

For Each c In Selection
c = WorksheetFunction.Clean(c)
Next c

End Sub

The first macro removes hard returns within cells. The Clean function removes all non printing characters so should be more successful

HTH


2016-03-10 10:54:50

Scott Renz

My problem is that some of the fields have carriage return or line field characters or both in them. When this happens, it starts a new row even though it should not be in a new row.

Is there a way to tell Excel not to start a new row when it reads the file in, if the end quote has not yet been encountered before coming to the line feed or carriage return characters?


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.