removing spaces in selected range

ryan_law2000

Well-known Member
Joined
Oct 2, 2007
Messages
738
So im looking for some code that will do the following:

When anything is typed into a cell in range B2:C20
remove all spaces after data is entered.

example:

"B 452 CV 120" (after enter is selected / or different cell selected then it will look like:
"B452CV120"

how can this be done?
I know there is a formula that can do this in a different cell but I'm trying to stay away from formulas in this case.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Perhaps something along these lines

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Intersect(Target, Range("B2:C20")) Is Nothing Then Exit Sub
If Target.Count > 1 Then
    For Each c In Target
        c.Value = Replace(c.Value, " ", "")
        
    Next c
Else:
    Target.Value = Replace(Target.Value, " ", "")
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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