Remove CHAR160 and standard spaces from entire sheet; not by column

angeloudaki

New Member
Joined
Jul 7, 2015
Messages
46
Issue:
I often import data from web pages where there is no 'export as' function which means I am often left with non-breaking spaces embedded (not visible in cells), or or leading/trailing spaces. This causes problems when using countif functions and also Conditional formatting (for duplicate values). This makes my calculations inaccurate.

Existing solution:
I know I can use the =TRIM(A1) for leading/trailing spaces and =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," "))) for non-breaking spaces but it is a pain when I have 20 columns. I currently create a helper column and just change the column reference then copy and paste as unformatted content to each column but when I have to do it a lot it is time consuming :(

All online help content points towards the cell reference formulae; and I couldn't find anything in the forum...

:)
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Would a macro solution be acceptable?
 
Upvote 0
I have never used Macros - ever - but I actually think they would pretty much solve most of my problems! If a macro is the only way - hit me with it - I will have a go. Learning curves welcome! I am the only one who uses this document so there is no problem with compatibility...
 
Upvote 0
To implement ..
1. With your workbook active press Alt+F11 to bring up the vba window.
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Press Alt+F8 to bring up the Macro dialog
6. Select the CleanUp macro & click ‘Run’
7. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

I'd suggest testing in a copy of your workbook and with a fairly small set of data to see how it goes.
If successful, then expand the data size.

Rich (BB code):
Sub CleanUp()
  With ActiveSheet.UsedRange
    .Value = Evaluate(Replace("if(len(#),trim(clean(substitute(#,char(160),"" ""))),"""")", "#", .Address))
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,726
Members
449,093
Latest member
Mnur

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