Remove extra space in a cell with formula

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello, I have too many rows in a sheet where some cells have an extra space. I want to remove it with the help of a formula in the same column or an adjacent column by which I can remove the extra space. I have already tried trim and substitute function but it doesn't help.
Query to remove space.xlsm
A
1X4361
2X5281
3X6805
4X9574
5X9596
6X11134
7X1634
8X2682
9X9127
10X9233
11X9338
12X9441
13X9514
14X9365
15X9387
16X9602
17X9671
18X9708
19X9115
20X9169
21X9564
22X9926
23X10488
24X8975
25X9237
26X9577
27X9609
Query
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
More than likely you have something called "non-breaking spaces" (ASCII 160). You cannot put a formula in the same column because a cell can only contain one thing... a formula or a constant (ignoring hyperlinks) but not both at the same time. So, you will need to put this formula in a different column (you can then copy paste its values over the constants in what I am assuming is Column )...

=SUBSTITUTE(A4,CHAR(160),"")
 
Upvote 0
More than likely you have something called "non-breaking spaces" (ASCII 160). You cannot put a formula in the same column because a cell can only contain one thing... a formula or a constant (ignoring hyperlinks) but not both at the same time. So, you will need to put this formula in a different column (you can then copy paste its values over the constants in what I am assuming is Column )...

=SUBSTITUTE(A4,CHAR(160),"")
Not working Rick. Still after applying the formula in the adjacent blank column & copy paste special, the space is still not removed.
 
Upvote 0
Using your sample, I brought into Power Query and ran a Trim against the range. It removed all extra spaces.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Column1", Text.Trim, type text}})
in
    #"Trimmed Text"

See below results
Book9
ABCDE
1Column1Column1Column2
2X43615X43615
3X52815X52815
4X68055X68055
5X9574 6X95745
6X9596 6X95965
7X111346X111346
8X16345X16345
9X26825X26825
10X91275X91275
11X92335X92335
12X9338 6X93385
13X9441 6X94415
14X95145X95145
15X93655X93655
16X93875X93875
17X9602 6X96025
18X96715X96715
19X97085X97085
20X91155X91155
21X91695X91695
22X9564 6X95645
23X99265X99265
24X104886X104886
25X89755X89755
26X92375X92375
27X9577 6X95775
28X96095X96095
Sheet1
Cell Formulas
RangeFormula
B2:B28B2=LEN(A2)
E2:E28E2=LEN([@Column1])
 
Upvote 0
Using your sample, I brought into Power Query and ran a Trim against the range. It removed all extra spaces.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Column1", Text.Trim, type text}})
in
    #"Trimmed Text"

See below results
Book9
ABCDE
1Column1Column1Column2
2X43615X43615
3X52815X52815
4X68055X68055
5X9574 6X95745
6X9596 6X95965
7X111346X111346
8X16345X16345
9X26825X26825
10X91275X91275
11X92335X92335
12X9338 6X93385
13X9441 6X94415
14X95145X95145
15X93655X93655
16X93875X93875
17X9602 6X96025
18X96715X96715
19X97085X97085
20X91155X91155
21X91695X91695
22X9564 6X95645
23X99265X99265
24X104886X104886
25X89755X89755
26X92375X92375
27X9577 6X95775
28X96095X96095
Sheet1
Cell Formulas
RangeFormula
B2:B28B2=LEN(A2)
E2:E28E2=LEN([@Column1])
Alansidman, I am still learning excel. I have no idea of power query. Can I apply a formula to do the above.?
 
Upvote 0
If it is actually a space try using
Excel Formula:
=TRIM(A2)
drag down as required
 
Upvote 0
Hi,

Seems you have Nonprintable (invisible) characters, try:

Book3.xlsx
ABCD
1X4361X436155
2X5281X528155
3X6805X680555
4X9574 X957465
5X9596 X959665
6X11134X1113466
7X1634X163455
8X2682X268255
9X9127X912755
10X9233X923355
11X9338 X933865
12X9441 X944165
13X9514X951455
14X9365X936555
15X9387X938755
16X9602 X960265
17X9671X967155
18X9708X970855
19X9115X911555
20X9169X916955
21X9564 X956465
22X9926X992655
23X10488X1048866
24X8975X897555
25X9237X923755
26X9577 X957765
27X9609X960955
Sheet714
Cell Formulas
RangeFormula
B1:B27B1=CLEAN(A1)
C1:D27C1=LEN(A1)
 
Upvote 0
Solution
Hi,

Seems you have Nonprintable (invisible) characters, try:

Book3.xlsx
ABCD
1X4361X436155
2X5281X528155
3X6805X680555
4X9574 X957465
5X9596 X959665
6X11134X1113466
7X1634X163455
8X2682X268255
9X9127X912755
10X9233X923355
11X9338 X933865
12X9441 X944165
13X9514X951455
14X9365X936555
15X9387X938755
16X9602 X960265
17X9671X967155
18X9708X970855
19X9115X911555
20X9169X916955
21X9564 X956465
22X9926X992655
23X10488X1048866
24X8975X897555
25X9237X923755
26X9577 X957765
27X9609X960955
Sheet714
Cell Formulas
RangeFormula
B1:B27B1=CLEAN(A1)
C1:D27C1=LEN(A1)
Thanks jtakw, Clean option worked. And I also found another way without using a formula. Select the data, select text to columns, delimited, space, finish. Your formula is better, My formula will work only with space in the end of a cell with no other spaces in the middle. Thanks once again
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top