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

Understanding Paragraph Alignment

One of the most basic ways to align paragraphs is to set the alignment used for the text in the paragraph. Word provides five ...

Discover More

Printing a Draft Watermark

Adding a watermark to the background of a printout can be challenging. This tip explains the different ways you can implement ...

Discover More

Displaying a Calendar

Want to know what today is? How about the date for next Thursday or the second Friday in October? Windows can display a handy ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Finding the Parent Folder

Do you need to figure out the name of the parent folder of whatever folder a worksheet is in? Believe it or not, this can be ...

Discover More

Finding the Size of a Workbook

Keeping tabs on the size of a workbook can be important when using Excel. You have a couple of options that will allow you to ...

Discover More

Invalid Names when Opening Workbook

Don't you hate opening a workbook and seeing error messages? If you see a message that some "invalid names" were detected in ...

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 3 + 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.