In some cases, numbers in a worksheet are actually formatted and stored in cells as text, which can cause problems with calculations or produce confusing sort orders. This issue sometimes occurs after you import or copy data from a database or other external data source.
Numbers that are formatted as text are left-aligned instead of right-aligned in the cell, and are often marked with an error indicator.
What do you want to do?
Technique 1: Convert text-formatted numbers by using Error Checking
If you import data into Excel from another source, or if you type numbers into cells that were previously formatted as text, you may see a small green triangle in the upper-left corner of the cell. This error indicator tells you that the number is stored as text, as shown in this example.
If this isn't what you want, you can follow these steps to convert the number that is stored as text back to a regular number.
-
On the worksheet, select any single cell or range of cells that has an error indicator in the upper-left corner.
How to select cells, ranges, rows, or columns
To select
Do this
A single cell
Click the cell, or press the arrow keys to move to the cell.
A range of cells
Click the first cell in the range, and then drag to the last cell, or hold down Shift while you press the arrow keys to extend the selection.
You can also select the first cell in the range, and then press F8 to extend the selection by using the arrow keys. To stop extending the selection, press F8 again.
A large range of cells
Click the first cell in the range, and then hold down Shift while you click the last cell in the range. You can scroll to make the last cell visible.
All cells on a worksheet
Click the Select All button.
To select the entire worksheet, you can also press Ctrl+A.
If the worksheet contains data, Ctrl+A selects the current region. Pressing Ctrl+A a second time selects the entire worksheet.
Nonadjacent cells or cell ranges
Select the first cell or range of cells, and then hold down Ctrl while you select the other cells or ranges.
You can also select the first cell or range of cells, and then press Shift+F8 to add another nonadjacent cell or range to the selection. To stop adding cells or ranges to the selection, press Shift+F8 again.
You cannot cancel the selection of a cell or range of cells in a nonadjacent selection without canceling the entire selection.
An entire row or column
Click the row or column heading.
1. Row heading
2. Column heading
You can also select cells in a row or column by selecting the first cell and then pressing Ctrl+Shift+Arrow key (Right Arrow or Left Arrow for rows, Up Arrow or Down Arrow for columns).
If the row or column contains data, Ctrl+Shift+Arrow key selects the row or column to the last used cell. Pressing Ctrl+Shift+Arrow key a second time selects the entire row or column.
Adjacent rows or columns
Drag across the row or column headings. Or select the first row or column; then hold down Shift while you select the last row or column.
Nonadjacent rows or columns
Click the column or row heading of the first row or column in your selection; then hold down Ctrl while you click the column or row headings of other rows or columns that you want to add to the selection.
The first or last cell in a row or column
Select a cell in the row or column, and then press Ctrl+Arrow key (Right Arrow or Left Arrow for rows, Up Arrow or Down Arrow for columns).
The first or last cell on a worksheet or in a Microsoft Office Excel table
Press Ctrl+Home to select the first cell on the worksheet or in an Excel list.
Press Ctrl+End to select the last cell on the worksheet or in an Excel list that contains data or formatting.
Cells to the last used cell on the worksheet (lower-right corner)
Select the first cell, and then press Ctrl+Shift+End to extend the selection of cells to the last used cell on the worksheet (lower-right corner).
Cells to the beginning of the worksheet
Select the first cell, and then press Ctrl+Shift+Home to extend the selection of cells to the beginning of the worksheet.
More or fewer cells than the active selection
Hold down Shift while you click the last cell that you want to include in the new selection. The rectangular range between the active cell and the cell that you click becomes the new selection.
To cancel a selection of cells, click any cell on the worksheet.
-
Next to the selected cell or range of cells, click the error button that appears.
-
On the menu, click Convert to Number. (If you want to simply get rid of the error indicator without converting the number, click Ignore Error.)
This action converts the numbers that are stored as text back to numbers.
Once you have converted the numbers formatted as text into regular numbers, you can change the way the numbers appear in the cells by applying or customizing a number format. For more information, see Available number formats.
Technique 2: Convert text-formatted numbers by using Paste Special
In this technique, you multiply each selected cell by 1 in order to force the conversion from a text-formatted number to a regular number. Because you're multiplying the contents of the cell by 1, the result in the cell looks identical. However, Excel actually replaces the text-based contents of the cell with a numerical equivalent.
-
Select a blank cell and verify that its number format is General.
How to verify the number format
-
On the Home tab, in the Number group, click the arrow next to the Number Format box, and then click General.
-
-
In the cell, type 1, and then press ENTER.
-
Select the cell, and then press Ctrl+C to copy the value to the Clipboard.
-
Select the cells or ranges of cells that contain the numbers stored as text that you want to convert.
How to select cells, ranges, rows, or columns
To select
Do this
A single cell
Click the cell, or press the arrow keys to move to the cell.
A range of cells
Click the first cell in the range, and then drag to the last cell, or hold down Shift while you press the arrow keys to extend the selection.
You can also select the first cell in the range, and then press F8 to extend the selection by using the arrow keys. To stop extending the selection, press F8 again.
A large range of cells
Click the first cell in the range, and then hold down Shift while you click the last cell in the range. You can scroll to make the last cell visible.
All cells on a worksheet
Click the Select All button.
To select the entire worksheet, you can also press Ctrl+A.
If the worksheet contains data, Ctrl+A selects the current region. Pressing Ctrl+A a second time selects the entire worksheet.
Nonadjacent cells or cell ranges
Select the first cell or range of cells, and then hold down Ctrl while you select the other cells or ranges.
You can also select the first cell or range of cells, and then press Shift+F8 to add another nonadjacent cell or range to the selection. To stop adding cells or ranges to the selection, press Shift+F8 again.
You cannot cancel the selection of a cell or range of cells in a nonadjacent selection without canceling the entire selection.
An entire row or column
Click the row or column heading.
1. Row heading
2. Column heading
You can also select cells in a row or column by selecting the first cell and then pressing Ctrl+Shift+Arrow key (Right Arrow or Left Arrow for rows, Up Arrow or Down Arrow for columns).
If the row or column contains data, Ctrl+Shift+Arrow key selects the row or column to the last used cell. Pressing Ctrl+Shift+Arrow key a second time selects the entire row or column.
Adjacent rows or columns
Drag across the row or column headings. Or select the first row or column; then hold down Shift while you select the last row or column.
Nonadjacent rows or columns
Click the column or row heading of the first row or column in your selection; then hold down Ctrl while you click the column or row headings of other rows or columns that you want to add to the selection.
The first or last cell in a row or column
Select a cell in the row or column, and then press Ctrl+Arrow key (Right Arrow or Left Arrow for rows, Up Arrow or Down Arrow for columns).
The first or last cell on a worksheet or in a Microsoft Office Excel table
Press Ctrl+Home to select the first cell on the worksheet or in an Excel list.
Press Ctrl+End to select the last cell on the worksheet or in an Excel list that contains data or formatting.
Cells to the last used cell on the worksheet (lower-right corner)
Select the first cell, and then press Ctrl+Shift+End to extend the selection of cells to the last used cell on the worksheet (lower-right corner).
Cells to the beginning of the worksheet
Select the first cell, and then press Ctrl+Shift+Home to extend the selection of cells to the beginning of the worksheet.
More or fewer cells than the active selection
Hold down Shift while you click the last cell that you want to include in the new selection. The rectangular range between the active cell and the cell that you click becomes the new selection.
To cancel a selection of cells, click any cell on the worksheet.
-
On the Home tab, in the Clipboard group, click the arrow below Paste, and then click Paste Special.
-
Under Operation, select Multiply, and then click OK.
-
To delete the content of the cell that you typed in step 2 after all numbers have been converted successfully, select that cell, and then press DELETE.
Some accounting programs display negative values as text, with the negative sign (–) to the right of the value. To convert the text string to a value, you must use a formula to 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.
Data | Formula |
---|---|
156- | =Left(A2,LEN(A2)-1)*-1 |
Technique 3: Apply a number format to text-formatted numbers
In some scenarios, you don't have to convert numbers stored as text back to numbers, as described earlier in this article. Instead, you can just apply a number format to achieve the same result. For example, if you enter numbers in a workbook, and then format those numbers as text, you won't see a green error indicator appear in the upper-left corner of the cell. In this case, you can apply number formatting.
-
Select the cells that contain the numbers that are stored as text.
How to select cells, ranges, rows, or columns
To select
Do this
A single cell
Click the cell, or press the arrow keys to move to the cell.
A range of cells
Click the first cell in the range, and then drag to the last cell, or hold down Shift while you press the arrow keys to extend the selection.
You can also select the first cell in the range, and then press F8 to extend the selection by using the arrow keys. To stop extending the selection, press F8 again.
A large range of cells
Click the first cell in the range, and then hold down Shift while you click the last cell in the range. You can scroll to make the last cell visible.
All cells on a worksheet
Click the Select All button.
To select the entire worksheet, you can also press Ctrl+A.
If the worksheet contains data, Ctrl+A selects the current region. Pressing Ctrl+A a second time selects the entire worksheet.
Nonadjacent cells or cell ranges
Select the first cell or range of cells, and then hold down Ctrl while you select the other cells or ranges.
You can also select the first cell or range of cells, and then press Shift+F8 to add another nonadjacent cell or range to the selection. To stop adding cells or ranges to the selection, press Shift+F8 again.
You cannot cancel the selection of a cell or range of cells in a nonadjacent selection without canceling the entire selection.
An entire row or column
Click the row or column heading.
1. Row heading
2. Column heading
You can also select cells in a row or column by selecting the first cell and then pressing Ctrl+Shift+Arrow key (Right Arrow or Left Arrow for rows, Up Arrow or Down Arrow for columns).
If the row or column contains data, Ctrl+Shift+Arrow key selects the row or column to the last used cell. Pressing Ctrl+Shift+Arrow key a second time selects the entire row or column.
Adjacent rows or columns
Drag across the row or column headings. Or select the first row or column; then hold down Shift while you select the last row or column.
Nonadjacent rows or columns
Click the column or row heading of the first row or column in your selection; then hold down Ctrl while you click the column or row headings of other rows or columns that you want to add to the selection.
The first or last cell in a row or column
Select a cell in the row or column, and then press Ctrl+Arrow key (Right Arrow or Left Arrow for rows, Up Arrow or Down Arrow for columns).
The first or last cell on a worksheet or in a Microsoft Office Excel table
Press Ctrl+Home to select the first cell on the worksheet or in an Excel list.
Press Ctrl+End to select the last cell on the worksheet or in an Excel list that contains data or formatting.
Cells to the last used cell on the worksheet (lower-right corner)
Select the first cell, and then press Ctrl+Shift+End to extend the selection of cells to the last used cell on the worksheet (lower-right corner).
Cells to the beginning of the worksheet
Select the first cell, and then press Ctrl+Shift+Home to extend the selection of cells to the beginning of the worksheet.
More or fewer cells than the active selection
Hold down Shift while you click the last cell that you want to include in the new selection. The rectangular range between the active cell and the cell that you click becomes the new selection.
To cancel a selection of cells, click any cell on the worksheet.
-
On the Home tab, in the Number group, click the Dialog Box Launcher next to Number.
-
In the Category box, click the number format that you want to use.
For this procedure to complete successfully, make sure that the numbers that are stored as text do not include extra spaces or nonprintable characters in or around the numbers. The extra spaces or characters sometimes occur when you copy or import data from a database or other external source. To remove extra spaces from multiple numbers that are stored as text, you can use the TRIM function or CLEAN function. The TRIM function removes spaces from text except for single spaces between words. The CLEAN function removes all nonprintable characters from text.
Turn off Error Checking
With error checking turned on in Excel, you see a small green triangle if you enter a number into a cell that has text formatting applied to it. If you don't want to see these error indicators, you can turn them off.
-
Click the File tab.
-
Under Help, click Options.
-
In the Excel Options dialog box, click the Formulas category.
-
Under Error checking rules, clear the Numbers formatted as text or preceded by an apostrophe check box.
-
Click OK.
No comments:
Post a Comment