VBA remove extra spaces

neveu

Board Regular
Joined
Jan 27, 2009
Messages
225
hello,

i have in a range several numbers that contain extra spaces and therefore these are recognized as text.

this is how the numbers would look : " 123.234.567"

could you please help me how to remove the extraspaces and the points (as otherwise this will also be recognized as text)?

thank you
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Use the Trim formula, your example would return it as text due to multiple full stops (.)
 
Upvote 0
Hi,

Try:

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

Using the above you don't need to TRIM and you get rid of the points.
 
Upvote 0
Try:

<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style=";">123.234.567</td><td style="text-align: right;;">123234567</td></tr></tbody></table><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><thead><tr style="background-color: #E0E0F0;text-align: center;color: #161120"><th><b>Sheet1</b></th></tr></td></thead></table><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #A6AAB6"><thead><tr style=" background-color: #E0E0F0;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">B1</th><td style="text-align:left">=VALUE(<font color="Blue">SUBSTITUTE(<font color="Red">SUBSTITUTE(<font color="Green">A1," ",""</font>),".",""</font>)</font>)</td></tr></tbody></table></td></tr></table><br />
 
Upvote 0
thank you,
I already have the Excel formula, but would need the VBA code so i could extend the formula to be applied only for the cells in my range where i have this situation; and in this case to copy the correct formated number ontop on the old value
 
Upvote 0
Then look to record a macro to apply your formula and adapt the code accordingly.
 
Upvote 0
If there are only single spaces at the beginning of the numbers you could use text to columns under the data menu to split the numbers out.
 
Upvote 0
Try:

Code:
Public Sub ReplaceChars()
Dim rng As Range, _
    LR  As Long
 
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    .EnableEvents = False
End With
 
LR = Range("A" & Rows.Count).End(xlUp).Row
For Each rng In Range("A1:A" & LR)
    rng.Value = Replace(Replace(rng.Value, " ", ""), ".", "")
Next rng
 
With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
    .EnableEvents = True
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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