Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
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.
Learn more about Allen...
Rick constantly uses ODBC and Microsoft Query to import data into a workbook, and Excel destroys the part numbers as they are imported. For example, part number "04E-106" is imported as 4.00E-106 with general formatting. The cell content after import is 4E-106, but that's not the correct part number. Rick wonders how to stop Excel from parsing the incoming data as a number in scientific notation.
This problem was already addressed in a different ExcelTip, relative to working with data imported from a CSV file:
The same cause of the problem detailed in that tip applies here, as well: Excel is interpreting the imported data as a number when it should be interpreting it as text. The general solution is to make sure that the cells into which your information will be imported are formatted as text before you actually do the import.
In most cases this will solve the problem. In some cases, however, you may need to look at the code you are using to do your import query. For instance, you may now be using the following command to import part numbers from your ODBC source:
SELECT part_num from ODBC.table
This simply brings the part number in from the source database without any changes; Excel then parses the incoming data trying to figure out what type of data it is. Instead you need to change the command in this way:
SELECT "'" + part_num AS part_num from ODBC.table
Note that this approach places an apostrophe at the beginning of the part number field as it is imported. This doesn't stop Excel from parsing the part number, but the added apostrophe forces Excel to treat the part number as text rather than a number.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7483) applies to Microsoft Excel 97, 2000, 2002, and 2003.
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!