How to Convert Text with Leading Spaces to Numbers in Excel
Question details
Convert numerical data that is formatted as text due to leading spaces into actual numbers so calculations can be performed.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Pasting data from a web page into a spreadsheet where numbers contain leading spaces, which formats them as text and prevents SUM and other calculation formulas from working.
- Observed behavior
- Formulas like SUM fail to calculate the data properly, and direct conversion attempts using just the VALUE function result in an "Error in Value" or wrong data type error.
Verify that the leading spaces in your cells are standard spaces. Web data often contains non-breaking spaces, which may require you to replace them before conversion.
Use VALUE, RIGHT, and LEN Functions to Convert Text to Numbers
This formula dynamically removes the first character (the leading space) regardless of the number's length and converts the remaining text string into a usable number.
The LEN function calculates the total characters in the cell. The RIGHT function extracts everything except the first character. Finally, the VALUE function converts this extracted text string into an actual numeric value.
Click on a blank cell adjacent to your data. For example, if your text data with leading spaces is in cell B2, click on C2.
Type the formula =VALUE(RIGHT(B2,LEN(B2)-1)) into the formula bar and press Enter.
Click the bottom-right corner of cell C2 and drag the fill handle down or across to apply the calculation to the rest of your data.
Copy the new formula cells, right-click the original data range, and select "Paste as Values" to permanently replace the text with actual numbers.

Use the Text to Columns Feature
Text to Columns is a quick, built-in tool that can re-evaluate and convert text data ranges into a general numeric format without using complex formulas.
Seamlessly Clean Web Data Imports in WPS Spreadsheet
WPS Office provides robust data handling tools that effortlessly remove leading spaces and convert imported web text into usable numbers. Enjoy a free, lightweight suite that supports all major spreadsheet functions.
- 1. Open Your Data: Launch WPS Spreadsheet and open the file containing the copied web data.
- 2. Select Problematic Cells: Highlight the range of cells where numbers are incorrectly stored as text due to leading spaces.
- 3. Access Text to Columns: Click on the Data tab in the top menu ribbon and select the Text to Columns tool.
- 4. Convert to Numbers: Choose Delimited, clear all delimiter checks, select General format, and click Finish to clean the data.

Frequently Asked Questions
Why doesn't the TRIM function work for converting these text numbers?
While the TRIM function successfully removes standard leading and trailing spaces, it leaves the cell's underlying data type as text. Furthermore, web data often contains non-breaking spaces which TRIM cannot remove by default.
Why do I get a #VALUE! error when using the VALUE function directly on my web data?
The #VALUE! error occurs because the VALUE function strictly expects text that represents numbers. If the cell contains unhandled characters like leading spaces or non-breaking spaces, it fails. The spaces must be stripped out first using RIGHT, MID, or SUBSTITUTE before wrapping the result in the VALUE function.
How can I tell if a number is stored as text in my spreadsheet?
By default, text is aligned to the left side of a cell, whereas true numbers are aligned to the right. Additionally, your spreadsheet application may display a small green triangle in the top-left corner of the cell, warning you that a number is formatted as text.




