Data Cleaning with the search function

jimmy2times

Board Regular
Joined
Aug 8, 2014
Messages
69
Hello I have a column in my tab called company name that needs data cleaning. The data looks like this
Company ABC-London
Company DEF-Manchester
Company A Ltd
Company B Ltd.
Company C,

I want to remove everything after the company name EG hyphen, comma, full stop,place.

The formula I am using is =left(A2(search(",",A2)-1). This works if I have a hyphen and the town. EG Company ABC-London but will return a #value error for the other examples provided.

Can the formula be adjusted to clean the other data entries without returning an error message? So the result should e
Company ABC
Company DEF
Company A Ltd
Company B Ltd
Company C

Any help would be much appreciated.

Kind Regards
 
A combined version works

=IF(IFERROR(SEARCH("-",A1),FALSE),LEFT(A1,SEARCH("-",A1)-1),SUBSTITUTE(SUBSTITUTE(A1,".",""),",",""))

It certainly compresses the formula

Thanks Tony,

In plain English, what is the formula doing to get the result?
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
My try on this one

=IFERROR(LEFT(A1,FIND(".",SUBSTITUTE(SUBSTITUTE(A1,"-","."),",","."))-1),A1)

It just replace all the unwanted characters with a full stop and then find it's position.
Then use the LEFT function to extract till one character before the full stop.
 
Upvote 0
My try on this one

=IFERROR(LEFT(A1,FIND(".",SUBSTITUTE(SUBSTITUTE(A1,"-","."),",","."))-1),A1)

It just replace all the unwanted characters with a full stop and then find it's position.
Then use the LEFT function to extract till one character before the full stop.

Thanks Sunny, brilliant in its simplicity.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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