How to remove white space from a number

13

2

I have a column of number with white spaces in them. Like this: "32 445 423". How do I get rid of all the white space to get excel to treat it as numbers rather than strings?

EDIT: Let me fill in some additional information that has come to light. My goal is to turn "32 445 423" into a 32445423. If I write in the string "32 445 423" into excel and use =SUBSTITUTE(A1;" ";"") it removes the spaces just fine. But the numbers I have are imported from a csv file. When running SUBSTITUTE on the imported numbers only leading and trailing spaces are removed.

Mr Alpha

Posted 2011-07-08T11:40:25.283

Reputation: 6 391

1hey, do you want to split that string in 3 numbers or just to threat this as one number (in that case, " " is like a number separator of each x1000)? – kokbira – 2011-07-08T13:19:24.663

Answers

9

I believe your imported data includes non-breaking spaces instead of standard spaces. Hence, the formula =SUBSTITUTE(A1," ","") does not work. Instead of using the space bar to type the " " in the SUBSTITUTE formula, try a non-breaking space. You can select this in the Character Map or use keystroke Alt+0160.

EDIT:

Since substituting regular spaces successfully removed the leading and trailing spaces, you should use nested Substitute formulas: one to sub the regular spaces and one to remove the no-break spaces.

=SUBSTITUTE(SUBSTITUTE(A1," ","")," ","")

You can copy this formula to try it in your workbook.

Excellll

Posted 2011-07-08T11:40:25.283

Reputation: 11 857

3+1 for considering non-breaking spaces. As an option, I also suggest using CHAR(160) to represent non-breaking spaces in your formula. – Ellesa – 2011-07-09T04:52:09.203

You were correct. The spaces in between the numbers were non-breaking spaces. With your substitute I was able to remove them. – Mr Alpha – 2011-07-10T11:34:53.330

1he could simply copy the space in between and using it to match that whitespace – None – 2011-07-10T11:48:10.703

6

Just do a search and replace over a group of cells you have selected, select your column and go to Home and Find and Select. Search for a space, and replace it with nothing.

jonsca

Posted 2011-07-08T11:40:25.283

Reputation: 3 889

1if he wants to split the string in 3 numbers, it is not ok. but if he wants to threat that string as only one number, it is ok. – kokbira – 2011-07-08T13:17:30.780

@kokbira He does not explicitly ask to split the numbers, as I interpreted "treat it as numbers" as meaning each cell would be a number. I can see where you are coming from in your interpretation, and that may very well be what he needs. – jonsca – 2011-07-08T13:21:08.207

6

Alternately if you want to retain the originally formatted number you can use the substitute function to provide a revised version of the string in another cell:

=SUBSTITUTE(A2," ","")

Jane T

Posted 2011-07-08T11:40:25.283

Reputation: 815

Oh sure, go the "high-tech" route :) Just kidding, nice one. – jonsca – 2011-07-08T12:16:39.167

This only removed the leading and trailing spaces, not the spaces in between the numbers. – Mr Alpha – 2011-07-08T12:34:02.490

1I did test it before posting and it correctly replaced all spaces. So I am not sure why it's not working for you. – Jane T – 2011-07-08T13:08:25.987

if he wants to split the string in 3 numbers, it is not ok. but if he wants to threat that string as only one number, it is ok. – kokbira – 2011-07-08T13:16:20.440

This does work fine (I'm using Excel 2007). Set cell A1 equal to =" 32 445 423 " and then set cell A2 equal to =SUBSTITUTE(A1, " ", ""), and the result is 32445423. – Breakthrough – 2011-07-08T13:24:15.910

depending on your regional settings, you can also substitute " " with "," (e.g. in USA 1234567=1,234,567) or "." (e.g. in Brazil 1234567=1.234.567). but "" is a better general solution. – kokbira – 2011-07-08T13:24:31.850

Curious. If I write in a number as string with spaces in it and do the substitute this method works fine. But it doesn't work for numbers as strings imported from a csv file. – Mr Alpha – 2011-07-08T13:31:50.210

2Weird. Usually, the formula above should work even with strings imported from a CSV. Try any of these and see if they work: =SUBSTITUTE(CLEAN(A2)), " ", "") or =SUBSTITUTE(A2,CHAR(160),"") – Ellesa – 2011-07-09T04:39:23.817

2

It sounds like you want to extract the numbers and put them in to separate columns. You can use the "Text to Columns" command, which is located on the Data tab (in Excel 2007). This walks you through a series of dialog boxes letting you specify how the fields are delimited and how you want the numbers formatted.

erichui

Posted 2011-07-08T11:40:25.283

Reputation: 844

if he wants to split the string in 3 numbers, it is ok. but if he wants to threat that string as only one number, it is not ok. – kokbira – 2011-07-08T13:21:13.943

2

This solution is to split 1 string with 3 numbers separated by spaces in 3 other numbers.

For didactic Purposes, let's consider:

     |    A    |    B    |    C    |    D    |    E    |
_____|_________|_________|_________|_________|_________|
     |         |         |         |         |         |
  1  |123 45 67|         |         |         |         |
_____|_________|_________|_________|_________|_________|
     |         |         |         |         |         |
  2  |         |         |         |         |         |
_____|_________|_________|_________|_________|_________|
     |         |         |         |         |         |
  3  |         |         |         |         |         |
_____|_________|_________|_________|_________|_________|
     |         |         |         |         |         |
  4  |         |         |         |         |         |
_____|_________|_________|_________|_________|_________|

So we can do that to help with next formulas:

For B1, where we start our search in A1 string - first character: =1
For C1, where is the first space in A1: =SEARCH(" ";A1;B1)
For D1, where is the second space in A1: =SEARCH(" ";A1;C1)
For E1, the length of string in A1: =LEN(A1)

And then what do you want:

For B2, to get first number: =SUBSTITUTE(A1;C1;C3-C1+1;"")
For C2, to get second number: =EXTRACT(A1;C1+1;D1-C1-1)
For D2, to get third number: =SUBSTITUTE(A1;B1;C2;"")

If you want, you can eliminate auxiliar formulas in B1:E1 including their contents in formulas in B2:D2

kokbira

Posted 2011-07-08T11:40:25.283

Reputation: 4 883

if he wants to split the string in 3 numbers, it is ok. but if he wants to threat that string as only one number, it is not ok. – kokbira – 2011-07-08T13:21:28.860

1

I had the same problem, a space occured as soon as my data had a 1000 plus value (so all numbers 1000+ looked like 3 333,00. I discovered that it was indeed the ALT+0160 character (I discoverd this by copying and pasting it word.

Quick fix to remove this "invisble char" is the following:

  1. Select a cell where the space occurs
  2. Select and copy ONLY the "space"
  3. Select entire worksheet (Ctrl +A)
  4. Start the find function (Ctrl + F)
  5. Go to the "replace" tab.
  6. "Find what" -> Paste your "space", "Replace with" -> Leave empty
  7. Select "Replace all"

Now all your data should be without spaces, and excel should see all data as Numbers.

JayZ

Posted 2011-07-08T11:40:25.283

Reputation: 11

0

Just use the text to column feature in data group .. and split your data using ""space"" option use ""concatenate"" to combine these number without spaces.

For Example:

32 445 423

use "text to column"
it will return

32|445|423

use concatenate formula, that will return your required format 32445423

FAKHAR.UZ.ZAMAN

Posted 2011-07-08T11:40:25.283

Reputation: 1

Welcome to Super User! Don't use all caps in your posts. No one wants to be screamed at. – Excellll – 2016-03-14T14:57:03.950

0

Sometimes a space in excel, are not a spaces, try to copy that "space" and pasted in replace dialog instead " ".

Rui Miguel Santos

Posted 2011-07-08T11:40:25.283

Reputation: 1

2What do you mean by "a space is not a space"? – Toto – 2017-09-20T10:36:15.323

0

Try this -

=VALUE(SUBSTITUTE(A2,CHAR(160),""))

Aziz Ahmad

Posted 2011-07-08T11:40:25.283

Reputation: 1

I believe that this works even without  VALUE(). – Scott – 2018-11-30T18:51:58.153

0

Quick to remove the "invisible char" at the "blank cell" in Worksheet as follows.

  1. Select a blank cell where the space occurs
  2. Copy the blank cell (Ctrl + C)
  3. Start the find function (Ctrl + F)
  4. Go to the "replace" tab.
  5. "Find what" -> Paste your "space", "Replace with" -> Leave empty
  6. Click "Option"
  7. Tick "Match entire cell contents"
  8. Select "Replace all"

P.S. The useful information is without affected.

user248182

Posted 2011-07-08T11:40:25.283

Reputation: 1

0

just copy your data into a .txt file and open the .txt file with excel, this will separate each column correctly into the worksheet...

nicojl

Posted 2011-07-08T11:40:25.283

Reputation: 11