XL2000: How to Convert Text to Number

ID: Q181298


The information in this article applies to:
  • Microsoft Excel 2000


SYMPTOMS

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, Microsoft Excel 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 you want to convert. This article describes methods for converting cells that contain text to numbers.


WORKAROUND

To convert text to numbers in a worksheet, use any of the following methods.

NOTE: Each of these methods assumes 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, under Category, click General, and then click OK.


Method 1: Retyping the Values in the Cells

On the Format menu, click Cells, and click the Number tab to change the number format of the cells. Then, retype the numbers.

Method 2: Select Edit Directly In Cell

To use this method, 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.


  3. Double-click the cell you want to format, and then press ENTER.


Method 3: Using Paste Special with Multiply

To use this method, follow these steps:
  1. In any blank cell, enter the value 1.


  2. Select the cell in which you typed 1 and 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.


Method 4: Removing Hidden Characters and Spaces

This method works best if the data is arranged in a single column or row. This technique 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 use this example, follow these steps:
  1. Insert a column to the right of column A by selecting column B and clicking Columns on the Insert menu.


  2. In the first cell of the inserted column (B1), type the following:


  3. 
          $B$1:   =VALUE(TRIM(CLEAN(A1))) 
  4. In column B, select all the cells to the right of the cells that contain data in column A.


  5. On the Edit menu, point to Fill, and then click Down.

    The new column contains the values of the text in column A.


  6. With the same range selected, click Copy on the Edit menu.


  7. Select cell A1, and click Paste Special on the Edit menu. Under Paste, click Values, and click OK to paste the converted values back on top of column A.


  8. Delete column B by selecting the column and clicking Delete on the Edit menu.


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

Method 5: Using a Visual Basic for Applications 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 Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
Create a Visual Basic for Applications macro to reenter the numbers in the selected cell or range of cells. To do this, follow these steps:
  1. Select the cells that exhibit the behavior.


  2. If you have not already done so, click Cells on the Format menu and click the Number tab to change the number format of the cells.


  3. Press ALT+F11 to open the Visual Basic Editor.


  4. On the Insert menu, click Module.


  5. Type the following macro code in the new module:


  6. 
          Sub Enter_Values()
              For Each xCell In Selection
                  xCell.Value = xCell.Value
              Next xCell
          End Sub 
  7. Press ALT+F11 to switch to Microsoft Excel.


  8. Reselect the affected cells if they are not already selected.


  9. On the Tools menu, point to Macro, and then click Macros. In the Macro name list, click Enter_Values. Click Run.


Method 6: Using Text to Columns

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 click Next.


  4. Under Delimiters, click to select the Tab check box, and 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.


  7. Click Finish.


The text is converted to numbers.


REFERENCES

For more information about cell formatting, click Microsoft Excel Help on the Help menu, type Format cells quickly in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Additional query words: XL2000

Keywords : xlformat
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: August 31, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.