Removing ALL spaces

xcellrodeo

Board Regular
Joined
Oct 27, 2008
Messages
206
Dear Mr Excel Community, I would like to request some help with removing spaces.
I have a data file which is a download .csv file which comes with alot of spaces between strings.
Having searched for solutions I have found some suggestions using the TRIM function.
This however appears to only remove leading/trailing spaces NOT the spaces between the words/nr.
What I need though is the removal of ALL spaces such as the following:
Example: STORE SPEND SEP-16
Outcome: STORESPENDSEP-16

Does anyone have an idea how this could be done?
Lastly, what I am looking for is 2 things:
1) a formula to achieve this cell by cell
2) a VBA code to do a complete column

Thanks all
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

gaz_chops

Well-known Member
Joined
Apr 29, 2003
Messages
6,485
Platform
  1. MacOS
Use the find and replace function.

Hit Ctrl F
Find space (enter with space bar)
Hit Replace
Replace all
 
Last edited:
Upvote 0

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
xcellrodeo,

Here is a macro solution for you to consider.

Sample raw data in the active worksheet:


Excel 2007
A
1STORE SPEND SEP-16
2STORE SPEND SEP-17
3STORE SPEND SEP-18
4STORE SPEND SEP-19
5
Sheet1


And, after the macro:


Excel 2007
A
1STORESPENDSEP-16
2STORESPENDSEP-17
3STORESPENDSEP-18
4STORESPENDSEP-19
5
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub RemoveALLSpaces()
' hiker95, 11/26/2016, ME977895
Application.ScreenUpdating = False
With ActiveSheet
  .Columns("A").Replace " ", "", xlPart
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the RemoveALLSpaces macro.
 
Upvote 0

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
Hiker95: I particularly liked your coding. Thanks again

xcellrodeo,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,195,716
Messages
6,011,274
Members
441,598
Latest member
chrispaulpearce

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
Top