Convert text to numbers in Excel

Sometimes I get a spreadsheet with a list of numbers in text format.

The fastest way I found to convert them into numbers was to select them and then run this little bit of VBA code, typed directly into the Immediate Window:

selection.value = selection.value

Before:

numbers before conversion

After:

numbers after conversion

Of course, if your numbers have leading zeroes, you'll need to make other arrangements. What do you do?

Related Articles:

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »

Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

comment bubble 17 Comments:

  1. Dan Chrome writes:

    Doesn't work for me in Excel 2003/2007 – I often have this issue (numbers and dates formatted as text) and it takes a bit of messing around to get it right… Would love a quick fix such as this – what am I doing wrong?

  2. David writes:

    I had to fix this for someone this week. I multiplied the numbers by 1. Your way is easier though. Good tip

  3. Harry Peltz writes:

    I usually do a text to columns on the offending data.. works like a charm.

  4. Tom writes:

    Hi,

    Sometimes numbers importet in excel come out with a ' before. Then I use the following macro to remove the apostrophe and make it available in excel as a number.

    Sub ExcelApostrophekesVerwijderen()
    Dim myRng As Range
    Dim myCell As Range

    Set myRng = Nothing
    On Error Resume Next
    Set myRng = Intersect(Selection, _
    Selection.Cells.SpecialCells(xlCellTypeConstants))
    On Error GoTo 0

    If myRng Is Nothing Then
    MsgBox "No constants in selection!"
    Exit Sub
    End If

    For Each myCell In myRng.Cells
    If myCell.PrefixCharacter "" Then
    myCell.Value = "" & myCell.Text
    End If
    Next myCell

    End Sub

    Please forgive me but i've forgotten where i've found the code. Dont sue me. :(

  5. Fio writes:

    Easy — type 1 in a cell, copy it, then select your range of text and "paste special" "multiply" and hey presto you have numbers.

    At this stage I have written a macro that does this and added it to a custom ribbon for ease of use.

  6. Dan writes:

    I also use the paste special -> multiply option

  7. Jon Peltier writes:

    Instead of Paste Special > Multiply by one, use Paste Special > Add zero. You can use a blank cell for zero, so you don't need to pollute and later clean up a blank cell.

    Even better, for one-column ranges, is Text-To-Columns, using fixed width without any splits.

  8. Rick Rothstein (MVP - Excel) writes:

    @Jon,

    I like the PasteSpecial method over the Text-To-Columns method because it will handle cells Formatted as Text that contain a number also.

  9. Jon Peltier writes:

    Rick -

    Good point. Both approaches use the formatting of the target cell, but pasting applies the formatting of the copied cell as it performs the operation. Try using paste-special-values with the operation: the cells will remain text.

  10. chrisham writes:

    Using the Text to Column feature is the easiest way for me.

  11. Chandoo writes:

    Excellent tip JP…

    I use text to column if the number is part of larger data set. Otherwise, use the paste special. But I like your one line code too.. will come handy when dealing with text thru VBA…

  12. Rick Rothstein (MVP - Excel) writes:

    @Chandoo… What "one line code"? I don't see any "one line code" in this thread… did I miss something?

  13. Vipul writes:

    There are many ways; most mentioned above. Another way would be to use =value() function
    But that leaves you with the numbers in a different location..
    In case you want it at the same location, then copy 1 typed in a different cell and paste special values n operator multiply onto these text cells.

  14. Kartik Sanghavi writes:

    Hey
    I want to convert Numerics including decimails in 1 cell of excel to text in another cell. I need a formula in excel that can do this for me.
    For eg
    Cell A1 = 235
    If i enter the formula in cell A2 it should output: "Two Hundred and Thirty Five" or Two Hundred Thirty Five"

  15. Vipul writes:
Comments on this article are closed. Why?

Site last updated: February 9, 2012