Remove Space from Text String

isleofman

New Member
Joined
Jan 12, 2010
Messages
38
I have a text sting in column A which includes spaces. I want to remove the spaces and import the now reduced text string into column B.

How would I do that using VBA?

I don't want to use =SUBSTITUTE(A1," ","") as I wish to change the text string in column A and when I change the text sting the =SUBSTITUTE(A1," ","") is then required to be re-entered in column B every time.

I hope somebody understands what I'm saying here!
Many thanks.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("A" & i)
        .Offset(, 1).Value = Replace(.Value, " ", "")
    End With
Next i
End Sub
 
Upvote 0
Code:
Sub test()
Range("A:A").Copy Range("B:B")
Range("B:B").Replace " ", ""
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,628
Messages
6,120,618
Members
448,973
Latest member
ChristineC

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