Formula required to clean simple formatting errors

manoj18071965

Board Regular
Joined
Sep 16, 2011
Messages
65
I have a long list in column A in excel. I am seeking for formula to clear below formatting errors:


  1. Remove Extra space or spaces appearing before text starts in a cell
  2. Remove Extra space or spaces appearing after text starts in a cell
  3. Remove comma if appearing at the end of text in a cell

Below is the example of output required:

Actual

Output Required
Assoc Prof.
Assoc Prof.
Assoc Prof.
Assoc Prof.
Assoc Prof.,
Assoc Prof.
Assoc Prof.,
Assoc Prof.
Assoc Prof.,
Assoc Prof.
Assoc Prof.,
Assoc Prof.
Assoc Prof.,
Assoc Prof.
Assoc Prof.,
Assoc Prof.
Assoc, Dean & Prof.
Assoc, Dean & Prof.
Assoc, Dean & Prof.
Assoc, Dean & Prof.
Assoc, Dean, Prof., and Dir.,
Assoc, Dean, Prof., and Dir.
Assoc, Dir., Jt. Degree Applied Legal Theory & Analysis Prog.,
Assoc, Dir., Jt. Degree Applied Legal Theory & Analysis Prog.
Assoc, Prof North- western
Assoc, Prof North- western
Assoc, Prof. & Dir.,
Assoc, Prof. & Dir.
Assoc, Prof. & Dir.,
Assoc, Prof. & Dir.
Assoc, Prof.
Assoc, Prof.
Assoc, Prof.
Assoc, Prof.
Assoc, Prof.
Assoc, Prof.
Assoc, Prof.
Assoc, Prof.

<tbody>
</tbody>
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Here you go... copy and paste entire formula to cell and make sure Column "A" has data.

=IF(TRIM(RIGHT(A2))=",",MID(CLEAN(TRIM(A2)),1,LEN(CLEAN(TRIM(A2)))-1),CLEAN(TRIM(A2)))
 
Upvote 0
Perhaps
=TRIM(REPLACE(TRIM(A1), LEN(TRIM(A1)), 1, SUBSTITUTE(RIGHT(A1),",","")))
 
Last edited:
Upvote 0
Here you go... copy and paste entire formula to cell and make sure Column "A" has data.

=IF(TRIM(RIGHT(A2))=",",MID(CLEAN(TRIM(A2)),1,LEN(CLEAN(TRIM(A2)))-1),CLEAN(TRIM(A2)))
That does not seem to work with data like "Assoc, Prof. & Dir.,  " (ie comma then space(s) at the end)



Perhaps
=TRIM(REPLACE(TRIM(A1), LEN(TRIM(A1)), 1, SUBSTITUTE(RIGHT(A1),",","")))
That does not seem to work with data like "Assoc, Prof. " (ie space(s) at the end with no comma immediately before)


My suggestion:
=LEFT(TRIM(A2),LEN(TRIM(A2))-1)&SUBSTITUTE(RIGHT(TRIM(A2)),",","")
 
Upvote 0
yeah, thats the perfect answer.

I got confused with this line "Remove comma if appearing at the end of text in a cell".


 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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