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

Converting Imported Information to Numeric Values

Written by Allen Wyatt (last updated October 24, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021


1

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

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12058) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021. You can find a version of this tip for the older menu interface of Excel 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

Rotating a Drawing Object

You can add all sorts of drawing objects to a document. Once placed, you can then rotate them to your heart's content. ...

Discover More

Creating a List of Cross-References

Cross-referencing has long been a capability in Word documents. You can easily add and remove cross-references but ...

Discover More

Hiding Individual Comments

When developing a document, a common practice is to use comments to discuss changes with other people or to make notes ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!

More ExcelTips (ribbon)

Leaving Trace Precedents Turned On

The Trace Precedents auditing tool can be quite helpful in seeing which cells "feed into" a particular formula. The ...

Discover More

Customizing Quick Access Toolbar Icons

The standard way to customize Excel is to add tools to the Quick Access Toolbar. The program provides only a limited ...

Discover More

Changing the Default Text Import Delimiter

When importing text into your worksheet, Excel defaults to using a comma as a delimiter. If you would prefer a different ...

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

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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 seven more than 2?

2020-10-25 00:42:49

Alex B

You do also have the option of transforming it when you import it.
Using the Excel File Open Text file import dialogue box, in the advanced option put a "space" in the thousands separator box. This is also works in Text to Columns after importing.
Or in Power Query transform the field by specifying the "Use Locale…" option and picking say French (Canada).


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu 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.