Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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: Defeating Automatic Date Parsing.
Written by Allen Wyatt (last updated September 28, 2019)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
Excel is normally pretty smart when it comes to importing data, but sometimes the automatic parsing it uses can be a real bother. For instance, you may import information that contains text strings, such as "1- 4- 9" (without the quotes). This is fine, but if you do a Replace to get rid of the spaces, Excel automatically converts the resulting string (1-4-9) to a date (1/4/2009).
One potential solution is to copy your information to Word and do your searching and replacing there. The problem with this solution is that when you paste the information back into Excel, it will again be parsed as date information and automatically converted to the requisite date serial numbers.
The only satisfactory solution is to make sure that Excel absolutely treats the resulting strings as just that—strings—and not as dates. This can be done in one of two ways: just make sure that the original text begins with either an apostrophe or a space. This can be ensured by using the Replace feature of Excel (depending on the data you have to work with) or by using the Replace feature of Word (which is much more versatile).
With an apostrophe or space at the beginning of the cell entry, you can remove additional spaces or characters from the cell contents. If the result is text that looks like a date, Excel will not parse it as such because the leading apostrophe or space forces treatment as text.
Another way to perform the task is to follow these steps. (Assume that the original data is in the range A2:A101).
=SUBSTITUTE(A2," ","")
Figure 1. The Paste Special dialog box.
If you are using Excel 2010 or a later version, you can use a shortcut for steps 8 through 10. When you click the down-arrow under the Paste tool (step 8), you see a small palette of options. Select the Values option in the Paste Values section of the drop-down list. The Values option is the left-most option in the Paste Values section; it looks like a clipboard with the number 123 on it.
These steps work because the output of the SUBSTITUTE function is always treated as text. When you copy and paste text values, they are treated as text with no additional parsing done by Excel.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9331) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Defeating Automatic Date Parsing.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Have you ever seen a worksheet in which some zero values have a negative sign in front of them? There's a reason for ...
Discover MoreWhen you create workbooks for others to use, you might want to make sure that they can't change the formatting and paper ...
Discover MoreWord provides a much wider range of formatting tools and options than you can find in Excel. One example is when it comes ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2019-09-30 09:17:43
JMJ
@Peter McNab
Thank you for this useful remark and the very clear example!
2019-09-29 22:08:18
Peter McNab
There is a third and simpler way.
It seems that Excel will parse entered values to match an existing format applied to a cell.
So if you know in advance that you will be entering part numbers, for example, that have a format like a date, just format the cells as text before you enter. Then your entries will not parsed as dates.
It also seems that Excel does not even attempt parsing fractions unless the cell is already formatted 'Fraction'.
(see Figure 1 below)
In the first row of this table, I have manually converted the data to text with a quote mark. The Type column contains the Excel Type() function which returns 1 for number, 2 for text, 4 for logical etc.
Figure 1. The result of formatting before vs after entering data
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 © 2024 Sharon Parq Associates, Inc.
Comments