Written by Allen Wyatt (last updated July 24, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
Patrick works in the financial sector, and he often has to import files to Excel. Many times these files contain, as one of many fields, what is referred to as a CUSIP number. This value is nine characters long and can contain both letters and digits. When importing, Excel drops any leading zeros, and if there is a letter E near the end of the value, Excel may convert the value to scientific notation. Patrick needs the CUSIP numbers to be imported without modification, so he wonders if there is an elegant (and easy) way to do this.
There are actually three approaches you can use to get the information in that you want. All of the methods assume that you are working with a text file that was output by some other system, other than Excel. The idea behind the approaches is to make sure that Excel, during the import, identifies the field containing the CUSIP numbers as text, instead of trying to convert the field content to numeric values.
Modify the Source
The first method is to modify the source file that you are working with. This could be as easy as talking to whoever controls the software that creates the import file. If you can get them to change how the CUSIP number is generated so that, in the file, the number is preceded by an apostrophe, then importing should be a snap. The apostrophe informs Excel that the field is text, and it will treat it accordingly. Plus, the apostrophe won't show up on the imported data once it is in a worksheet.
You could also load the source file in a text editor and add the apostrophes yourself, but this may be a quite tedious task if there are many records in the file or if you need to work with many files over time.
Modify Your Traditional Import
Again, assuming you are importing a delimited file (either comma delimited to tab delimited), then you can follow these steps to have the file imported correctly:
Figure 1. The Text Import Wizard.
Use Power Query to Import the Data
Assuming you are using at least Excel 2016, you can use Power Query to load your data. Power Query seems to be all the rage these days, and it really does make the importation of data quite easy. Just follow these general steps:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13887) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.
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!
If you open a workbook and notice that Excel displays two windows for it, this has to do with how the workbook was saved. ...
Discover MoreWhen processing plain text files in a macro, it is often helpful to know how much data the file contains. The normal way ...
Discover MoreDo you need to figure out the name of the parent folder of whatever folder a worksheet is in? Believe it or not, this can ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-07-26 06:43:01
JMJ
@ Roy
Thanks for this hidden gem!
I do agree with you about the shortkeys, that changed with each and every version of Excel (You want to upgrade? Then re-learn them all!) and now tend to disappear...
J-M
2021-07-24 17:42:08
Roy
If you wish to use the decades old Text Import Wizard that is used in the first method (and that used to present itself without effort on your part but now... not so much), select:
Data | Get Data | Legacy Wizards | From Text (Legacy) (or press: Alt-A-PN-W-T)
No need to rename a file. I mention it because — for some WEIRD reason, people HATE that like they hate seeing "helper column" or "Named Range" or "macro" — even though you have the File | Open dialog up and are selecting the file, how hard is it to rename it right then and there, THEN select it?
I also find it of interest that when you hit "Alt" just to see the shortcut that goes with it for the menu, um, oh yeah, they call that menu "The Ribbon" like it isn't STILL just a menu, you DO NOT see the shortcuts for the next level and so are greatly discouraged from learning keyboard shortcuts to your choices. (Like who would EVER hit Alt-D to get the Data menu, then want to move over to the mouse and search further down the menu trees to the command he wants? Why wouldn't a mouse-y person like that just take the mouse from the start? If someone presses the Alt-D shortcut, he SURELY value (after relearning the pleasures of keying and never reaching over for the mouse (talk about slowing down!)) seeing the shortcut tags for the commands at each level of the menuing he accesses so even if he never plans to learn more than a few, he can always easily reach the DEEP submenu that does his desire without ever reaching off the keyboard... BECAUSE the labels are there and he never had to learn the key combinations (which he didn't really want to do) to use them! So if you mouse into the Ribbon, it should look like today, no keyboard help, just mouse-y choices. If you keyboard into it, the level you are on should ALWAYS show its shortcuts, no forcing it to required.
Anyway, if you eschew pressing the Alt-D after learning it will not actually show those next menu-level shortcuts, here's what you need (and for some reason ("some" 'cause I know MS stopped rewarding MS Expert shills for denigrating non-mouse-y use of their new menu a VERY long time ago) sites do not ever tell you how to get the next level going. (Once you get past the second menu level, individual choices actually often still use the "underscore a letter in a choice's description" mechanism, so you can use that, usually, for third-fourth-fifth and so on menu-levels finding your command.)
It is to press Alt-A. if wanting to use the Data submenu. Alt-M for the Formula submenu, Alt-R for the Review submenu, and so on. In other words, the old top level menu in Excel (2003 and before) had "underscore a letter" markings, A for Data, M for formula, and so on, that you used to go right into them and the Ribbon STILL does, though they mask it by not underscoring any letters. But they all still work, even ones that didn't exist in the usual top-level menu 2003 and prior offered. Experimenting (on a new, blank file...) will show you all of them as might a search of the internet.
In any case, press Alt-A instead of Alt-D and you get the tags shown for the second-level menu the Data tab on The ("I'm not a menu, I'm so not a menu, geez, will you stop hating me for being a menu that takes up a quarter of your screen, I mean no, I'm not even a menu anyway...") Ribbon rather than the basically useless simple showing of the Data submenu.
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