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, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Correctly Saving Delimited Files.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
If you need to stuff the current workbook's filename and path into a cell or a header or footer, you'll appreciate the ...
Discover MoreWhen dealing with files containing comma-separated values, you want to make sure that what gets imported into Excel ...
Discover MoreWhen storing your Excel workbook, you need to specify a file name to be used for the workbook. Take a moment to consider ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2019-01-08 11:26:38
Neil
Eoin- if you are importing a CSV file into Excel, you can specify the format of each column in the data. If you select "text" for the page number data, it should keep Excel from converting to dates. (see Figure 1 below)
Figure 1.
2019-01-08 06:11:59
Eoin Bairéad
Hi. As usual, excellent tip. I have a problem. I have a CSV file of book entries which includes author, title and pagination. Pagination is in the format 105-110
Unfortunately early pagination doesn't work, and 1-10 comes out as January 10th, 3-8 as March 8th and so on.
Is there a fix?
Thanks
Eoin
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?
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 © 2021 Sharon Parq Associates, Inc.
Comments