VBA Convert Range to Number: 4 Ways

VBA & macros · Updated November 23, 2026

To convert a range of text-formatted numbers to actual numeric values in Excel VBA, use the Value property of the range object: Range("A1:A10").Value = Range("A1:A10").Value. This single line forces Excel to re-evaluate each cell’s content as a number, and it works for most common cases where cells contain numbers stored as text (e.g., from imported files or leading apostrophes).

Why Text Numbers Cause Problems

Excel treats a cell containing "123" (text) differently from 123 (number). Text numbers are left-aligned by default, show a green triangle warning in the corner, and break formulas like SUM or AVERAGE because they are ignored. This often happens when data comes from CSV files, web queries, or other systems that export numbers as strings. Converting them to real numbers ensures calculations work and the data sorts correctly.

Method 1: The Value-to-Value Trick (Fastest)

The simplest approach is to assign the range’s Value back to itself. This works because VBA reads the values as strings, then writes them back as numbers when the source is a text representation of a number.

Sub ConvertRangeToNumber()
    Dim rng As Range
    Set rng = ThisWorkbook.Sheets("Sheet1").Range("A1:A100")
    rng.Value = rng.Value  ' Re-evaluates as numbers
End Sub

This method is fast and does not change cell formatting. It works for entire columns or non-contiguous ranges (use Union if needed). It does not work if the cells contain non-numeric text or dates stored as text—those will remain text.

Method 2: Using PasteSpecial with Multiply

Another reliable technique is to copy the range and use PasteSpecial with the Operation:=xlMultiply by a dummy cell containing the number 1. Multiplying any number by 1 yields the same number, but Excel converts text numbers to numeric during the operation.

Sub ConvertWithPasteSpecial()
    Dim rng As Range
    Dim dummy As Range
    Set rng = ThisWorkbook.Sheets("Sheet1").Range("B2:B50")
    Set dummy = ThisWorkbook.Sheets("Sheet1").Range("Z1")
    dummy.Value = 1
    dummy.Copy
    rng.PasteSpecial Paste:=xlPasteValues, Operation:=xlMultiply
    Application.CutCopyMode = False
    dummy.ClearContents
End Sub

This method is especially useful when the range contains a mix of text numbers and real numbers—it converts only the text ones. It also handles numbers with leading zeros (like ZIP codes) by preserving them as text if they have a leading apostrophe, but if they are plain text, they will be converted to numbers and lose leading zeros.

Method 3: Looping Through Cells (Slow but Flexible)

For cases where you need to check each cell individually (e.g., to skip blanks or handle errors), loop through the range and use IsNumeric to test each cell’s value before converting.

Sub LoopConvert()
    Dim cell As Range
    For Each cell In ThisWorkbook.Sheets("Sheet1").Range("C1:C100")
        If IsNumeric(cell.Value) And Not IsEmpty(cell.Value) Then
            cell.Value = CDbl(cell.Value)  ' Convert to Double
        End If
    Next cell
End Sub

This approach is slower for large ranges (thousands of cells) but gives you control. Use CLng if you need integers, or CDec for high-precision decimals. Note that IsNumeric returns True for strings like “1,000” (with comma), but CDbl may error on those—use Val() or clean the string first if needed.

Method 4: Using Text-to-Columns via VBA

Excel’s built-in Text-to-Columns feature (Data > Data Tools > Text to Columns) can convert a column of text numbers without changing the delimiter. In VBA, use the TextToColumns method with the xlDelimited format and no delimiters.

Sub TextToColumnsConvert()
    Dim rng As Range
    Set rng = ThisWorkbook.Sheets("Sheet1").Range("D1:D100")
    rng.TextToColumns Destination:=rng, DataType:=xlDelimited, _
        TextQualifier:=xlTextQualifierDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, _
        Comma:=False, Space:=False, Other:=False
End Sub

This method is robust for columns with a single data type and also handles dates stored as text (converts to real dates). It changes the cell format to General, which may be undesirable if you had custom number formats.

Choosing the Right Method

  • Speed: Value-to-value trick is fastest for large ranges.
  • Mixed data: PasteSpecial Multiply handles mixed text/numbers safely.
  • Need to skip blanks or errors: Loop with IsNumeric.
  • Dates as text: Text-to-Columns works best.
  • Preserve leading zeros: Avoid all methods—keep as text.

Common Pitfalls and Misconceptions

One common misconception is that setting NumberFormat to “General” or “0” will convert text to numbers—it does not. Number format only changes how a numeric value displays; it has no effect on text. Another pitfall is using CDbl on a cell that contains a formula returning text—this will error. Always test IsNumeric first. Also, if your range includes cells with errors like #VALUE!, the Value-to-value trick will propagate errors—use On Error Resume Next or filter first.

Frequently Asked Questions

Does this work on a whole column without specifying rows?

Yes, you can use Range("A:A") to reference an entire column. The Value-to-value trick will convert all non-empty cells in that column. Be cautious with entire columns because it may process millions of cells and slow down—limit to used range with UsedRange if possible.

How do I convert a range to numbers without losing leading zeros?

You cannot convert text numbers with leading zeros (like “00123”) to numeric values without losing the zeros, because numeric values do not store leading zeros. If you need to keep them, leave the cells as text. Alternatively, use a custom number format like "00000" to display zeros, but the underlying value will be 123.

Why does my SUM formula still ignore converted cells?

If you used the Value-to-value trick and SUM still ignores them, check if the cells contain a space or non-breaking space character (common in imported data). Use Trim or Clean in VBA to remove extra characters before converting. Also, ensure the cells are not formatted as Text—right-click > Format Cells > General, then re-run conversion.

Can I convert a range to numbers without changing the cell format?

Yes, the Value-to-value trick and PasteSpecial method do not change the cell’s number format. Only Text-to-Columns resets to General. If you want to keep a specific format like currency or percentage, apply it again after conversion.

Is there a way to convert numbers stored as text in an entire workbook?

Yes, loop through all worksheets and used ranges, but be careful with performance. Use a nested loop over Worksheets and UsedRange, applying the Value-to-value trick to each range that contains text numbers. This is slow for large workbooks—consider a manual approach or a more targeted macro.

Before running any macro that modifies cell values, save a copy of your workbook—macros cannot be undone with Ctrl+Z. This is especially important if you are converting an entire column or workbook, as the original text data will be overwritten.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.