In Excel I am trying to use Find and Replace on some data to remove everything after a double space. An example of this data is…
The Apples are Green They are supplied by John
The Bannanas are Yellow They are supplied by Tom
The Strawberries are Red They are supplied by Jason
I want the data to look like this…
The Apples are Green
The Bannanas are Yellow
The Strawberries are Red
In Openoffice I can search for ‘ .*’ and replace it with nothing and this works, but with Excel it doesnt.
I do eventually want to work this into a macro but for now I am just trying to get it to work with Find and Replace, can anyone help?
Here’s an alternative way of doing what you are trying to accomplish. I find it gives you more control than
FindandReplace.The above operates on only one cell. To do the same over many cells, you could do this:
As has been pointed out in other answers, you should replace any troublesome non-break spaces (
Chr(160)) by regular spaces, prior to searching for double spaces:EDIT Addressing @chris neilsen’s comment:
If some of your target cells are devoid of double spaces, then you should check for that prior to using the
Leftfunction lest it raise an error:Now, on the very remote chance that some of the target cells contain formulas comprising double spaces (e.g.
=A1 & "<space><space>" & A2), these formulas will be replaced by values. To avoid this, change the conditional toIf i > 0 And Not cell.HasFormula Then.