Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Converting Imported Information to Numeric Values.

Converting Imported Information to Numeric Values

by Allen Wyatt
(last updated August 12, 2015)

4

Garrett asked if there was a way to quickly convert text data to numerical data. He is importing a text file that uses spaces in the thousands place (1 256) instead of a comma (1,256).

There are several ways to approach this problem. The first is to understand the source of the problem. The text file is probably created on a system that is following a metric standard. Some countries, following the metric standard, use a space for a thousands separator instead of a comma. Thus, you could import the file properly into Excel if you change your regional settings in Windows before starting Excel and doing the import. You can change the regional settings by using the Regional Options applet in the Control Panel.

If you don't want to change the regional settings on your system, there are other approaches you can take. After Excel imports the information, you can select the range of cells that contain numbers and simply do a search and replace. You are searching for a single space and replacing it with nothing. This does away with the space completely, and Excel will then treat the contents of the cell as a number.

You can also use a formula, if desired, to modify the imported data. For instance, if the imported number (containing a space) is in cell A3, you could use this formula to strip out the space:

=1*SUBSTITUTE(A3," ","")

Note that there is a space between the first set of quotes and nothing between the second set of quotes.

If you have quite a bit of data to convert, or if you have text interspersed with the "numbers-only" cells, then you may decide to use a macro to do the conversion. The following macro works on a selection you make before calling it. It also checks to make sure that the cell—after removing the spaces—contains a numeric value. If it doesn't, then no conversion is done.

Sub ClearSpacesIfNumeric()
    Dim c As Range 'Cell under examination
    Dim tmpText As String 'Cell contents without spaces
    Dim i As Integer 'Simple counter

    For Each c In Selection
        tmpText = "" 'Initialize

        'Check each character to see if it's a space
        'If it isn't, add it to tmpText
        For i = 1 To Len(c.Text)
            If Mid(c.Text, i, 1) <> " " Then
                tmpText = tmpText & Mid(c.Text, i, 1)
            End If
        Next i

        'tmpText is now the cell contents without spaces
        'If tmpText is a number, assign its value to
        'the current cell
        If IsNumeric(tmpText) Then
            c.Value = tmpText
        End If
    Next c
End Sub

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2248) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Converting Imported Information to Numeric Values.

Author Bio

Allen Wyatt

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

MORE FROM ALLEN

Controlling the Format of Cross-References

When you use fields to add cross-references to tables or figures, Word normally takes care of formatting the words used in ...

Discover More

Editing While Spell-Checking

When you run a spell-check on a document, you may end up seeing other things that need to be edited. Never fear; you can do ...

Discover More

Saving All Open Workbooks

Wouldn't it be nice to have a single command that would save each of you open workbooks, all at once? It's easy to do with ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

MORE EXCELTIPS (MENU)

Changing Links

If your worksheet is linked to data in other worksheets, you may need to change the link from time to time. Here's how to ...

Discover More

Excel Applies Scientific Notation to Imported Data

Using Excel to import data from another source (such as a database) is a great approach to analyze that data. What do you do, ...

Discover More

Getting Rid of Empty Rows after Importing

Import data into a worksheet (or paste it there) and you may find that you end up with a group of blank cells you need to get ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 3 - 0?

2015-08-13 06:23:41

Enduser

If you are not doing this all the time and want a quick method you can:

Select the entire column by clicking on the letter(s) for that column.
From the "DATA" on the ribbon click on the "TEXT TO COLUMNS."
When the dialogue box pops up click on "Finish" and you're done.


2014-05-14 16:32:54

Hartmut Blau

Sub text_num()
ActiveCell = Val(ActiveCell) ' "111 222"
ActiveCell.NumberFormat = "0" ' 111222
End Sub


2014-05-14 15:58:42

Hartmut Blau

Sub text_num()
Dim LNumber
LNumber = Val(ActiveCell) 'activecell = "111 222"
ActiveCell = LNumber
ActiveCell.NumberFormat = "0" 'activecell = 111222
End Sub


2012-08-27 10:10:09

Nancy Lelle

For those of us who are not macro savy, my quick fix to convert text into numeric is the following:

1.Enter the number one in a cell off to the side and copy it.
2.Select the cells or columns that you want to convert.
3.Paste special and choose both to paste formulas and number formats and operation multiply.


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing