Microsoft KB Archive/822665

= How to convert text to numbers in Excel 2003 =

PSS ID Number: 822665

Article Last Modified on 10/6/2004

-

The information in this article applies to:


 * Microsoft Office Excel 2003

-







For a Microsoft Excel 2002 version of this article, see 291047.



For a Microsoft Excel 2000 version of this article, see 181298.

IN THIS TASK

 * SUMMARY
 * ** How to Convert Text to Numbers
 * *** Method 1: Use the Error Button
 * Method 2: Retype the Values in the Cells
 * Method 3: Edit Directly in the Cell
 * Method 4: Use the Paste Special Command
 * Method 5: Remove Hidden Characters and Spaces
 * Method 6: Use a Microsoft Visual Basic for Applications (VBA) Procedure
 * Method 7: Use the Text to Columns Command
 * REFERENCES



SUMMARY
This step-by-step article describes how to convert cells that contain text to cells that contain numbers.

When you import a file that was created in another program (such as dBASE or Lotus 1-2-3) or that was downloaded from a mainframe, Excel 2003 may recognize some numbers as text.

This causes functions such as SUM and AVERAGE to ignore the values in these cells. These text strings may contain actual text in addition to the numbers that you want to convert.

back to the top

How to Convert Text to Numbers
To convert text to numbers in a worksheet, use any of the methods described in this article (Methods 1 through 7).

Note Each of these methods assumes that you have already changed any cell number formatting in the cells to General. To do this, follow these steps:
 * 1) On the Format menu, click Cells.
 * 2) On the Number tab, click General under Category, and then click OK.

back to the top

Method 1: Use the Error Button
If the cells where numbers appear as text contain an error indicator in the upper-left corner, follow these steps.

Note This method assumes that background error checking has been turned on in Excel. If error checking is not turned on, you must turn it on for this method.
 * 1) On the Tools menu, click Options.
 * 2) Click the Error Checking tab.
 * 3) Click to select the Enable background error checking check box.
 * 4) Click to select the Number stored as text check box.
 * 5) Click to select other rules that you may want to turn on.
 * 6) Click OK.
 * 7) Click the cell that contains the error indicator.
 * 8) Click the error button next to the cell, and then click Convert to Number.

back to the top

Method 2: Retype the Values in the Cells
To retype the values in the cells, follow these steps:
 * 1) On the Format menu, click Cells, and then click the Number tab to change the number format of the cells.
 * 2) Retype the numbers.

back to the top

Method 3: Edit Directly in the Cell
To edit directly in the cell, follow these steps:
 * 1) On the Tools menu, click Options.
 * 2) On the Edit tab, verify that the Edit directly in cell check box is selected.

Click OK.
 * 1) Double-click the cell that you want to format, and then press ENTER.

back to the top

Method 4: Use the Paste Special Command
To use the Paste Special command, follow these steps:
 * 1) In any blank cell, type the value 1.
 * 2) Select the cell where you typed 1, and then click Copy on the Edit menu.
 * 3) Select the cells with the values that you want to convert to numbers.
 * 4) On the Edit menu, click Paste Special.
 * 5) Under Operation, click Multiply.

Under Paste, click Values, and then click OK.
 * 1) Delete the value 1 that you typed in the blank cell.

Note Some accounting programs display negative values with the negative sign (–) to the right of the value. To convert the text strings to values, you must return all the characters of the text string except the rightmost character (the negation sign), and then multiply the result by –1. For example, if the value in cell A2 is 156– the following formula converts the text to the value –156:

=LEFT(A2,LEN(A2)-1)*-1

back to the top

Method 5: Remove Hidden Characters and Spaces
This method works best if the data is arranged in a single column or row. This method uses the TRIM function and the CLEAN function to remove extra spaces and nonprinting characters that may be imported with the file. The following example assumes that the data is in column A and starts in row 1 ($A$1). To remove hidden characters and spaces, follow these steps:  Insert a column to the right of column A.

To do this, click column B, and then click Columns on the Insert menu.  In the first cell of the inserted column (B1), type the following: $B$1: =VALUE(TRIM(CLEAN(A1)))  In column B, select all the cells to the right of the cells that contain data in column A. On the Edit menu, point to Fill, and then click Down.

The new column contains the values of the text in column A. With the same range selected, click Copy on the Edit menu. Click cell A1, and then click Paste Special on the Edit menu.

Under Paste, click Values, and then click OK to paste the converted values back on top of column A.</li> Delete column B.

To do so, click the column, and then click Delete on the Edit menu.</li></ol>

The text that was in column A is in a number format.

Note This method may not remove all nonprinting white space characters. For example, the white space character Chr$(160) will not be removed.

back to the top

Method 6: Use a Microsoft Visual Basic for Applications (VBA) Procedure
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

http://www.microsoft.com/partner/referral/

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Create a VBA macro to reenter the numbers in the selected cell or range of cells. To do this, follow these steps: <ol> Select the cells that you want to convert.</li> If you have not already done so, click Cells on the Format menu, and then click the Number tab to change the number format of the cells.</li> Press ALT+F11 to start the Visual Basic Editor.</li> On the Insert menu, click Module.</li>  Type the following macro code in the new module: Sub Enter_Values For Each xCell In Selection xCell.Value = xCell.Value Next xCell End Sub </li> Press ALT+F11 to switch to Excel.</li> Select the cells that you want to convert, if they are not already selected.</li> On the Tools menu, point to Macro, and then click Macros.

In the Macro name list, click Enter_Values. Click Run.</li></ol>

back to the top

Method 7: Use the Text to Columns Command
This method works best if the data is arranged in a single column. The following example assumes that the data is in column A and starts in row 1 ($A$1). To use this example, follow these steps:
 * 1) Select one column of cells that contain the text.
 * 2) On the Data menu, click Text to Columns.
 * 3) Under Original data type, click Delimited, and then click Next.
 * 4) Under Delimiters, click to select the Tab check box, and then click Next.
 * 5) Under Column data format, click General.
 * 6) Click Advanced and make any appropriate settings for the Decimal separator and Thousands separator.

Click OK.
 * 1) Click Finish.

The text is converted to numbers.

back to the top

<div class="moreinformation_section">

MORE INFORMATION
For more information about cell formatting, click Microsoft Excel Help on the Help menu, type format cells in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

The third-party products that are discussed in this article are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.

back to the top

Additional query words: prb XL2002 xl2003

Keywords: kbfunctions KbVBA kbconvert kbhowto KB822665

Technology: kbExcel2003 kbExcel2003Search kbExcelSearch kbExcelWinSearch

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.