Conditional format for removing trailing and leading spaces.

Eamonn100

Board Regular
Joined
Nov 12, 2015
Messages
156
Hi,

I'm using this formula to remove any trailing or leading spaces. =TRIM(CLEAN(A1)) It works fine but is there anyway that I can use it as a conditional format so that when I paste the information onto the page it removes any trailing or leading spaces.

At the moment I have to use this formula on a second page to get the spaces removed. I'm trying to get this on to my original page that I paste onto because other formulas are returning error when reading from the second sheet.

Thanks in advance.
 
Last edited:
The code still didn't work. Maybe I'll have to upload a copy of the sheet?

Anyway thanks for now but it's my bed time. I've been on the computer all day and need sleepy time. I'll reply again tomorrow.

Thanks for your help.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Find any entry which has a leading space. Let's say it is in cell A10. Then put this formula and see what it returns:
Code:
=CODE(LEFT(A10,1))
It should return 32.
If it returns some other number, then you do not have a normal space, but some other special character in there.
 
Last edited:
Upvote 0
Ok rested and ready.

The names with a leading space (on the left) have returned 32. I also experimented and incerted a leading space and the number changed to 32.

Also, almost all values in column A have a trailing (on the right) space, (if this helps).
 
Upvote 0
Oh, I've worked out a work around.

I opened up a second company sheet and in column A used the formula =TRIM(CLEAN(Company!A1)). Though for some reason using that formula I could not format any of the results. So for all the other columns on Company2 sheet i just use =Company!A1.

Anyway, I'm still interested in what solution you can come up with as with everything in excel I learn something new.
 
Upvote 0
Based on everything that you have told me, the solutions that I gave you should work. I tested it out myself, and confirmed that it does.
If they do not, then I suspect you are not doing something correctly. Most likely, you are not putting the VBA code in the correct place. It needs to be put in the appropriate Sheet tab in VBA BEFORE you paste your data to that sheet.

So, if you were copying/pasting the data into Sheet2, you would need to first paste the VBA code that I gave you to the Sheet2 module in VBA before you copy and paste your data.

A few other things to confirm:
- The data you are copying/pasting is hard-coded data, right? They are not formulas that you are copying, are they?
- How exactly are you copying/pasting data to this sheet? What methodology are you using?
 
Upvote 0
Yes, Event Procedures, which run automatically, have some strict requirements. They are not exactly like the regular Procedures and Functions that you create and place in Standard Modules.
They must:
- be named a certain way (no flexibility there)
- be placed in the proper module
If both those requirements are not met, they will not automatically fire.

Here is a good write-up on them: http://www.cpearson.com/excel/events.aspx
 
Upvote 0
Thanks for this. I think it's time to begin to learn about VBA,codes,macros and the like as I know nothing about them/it, (as you have seen).

A few links that you would recommend for VBA,code,macros for dummies would be appreciated.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,109
Members
452,302
Latest member
TaMere

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