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:
[TABLE="width: 812"]
<tbody>[TR]
[TD]
Actual

[/TD]
[TD]Output Required
[/TD]
[/TR]
[TR]
[TD]Assoc Prof.
[/TD]
[TD]Assoc Prof.
[/TD]
[/TR]
[TR]
[TD]Assoc Prof.
[/TD]
[TD]Assoc Prof.
[/TD]
[/TR]
[TR]
[TD] Assoc Prof.,
[/TD]
[TD]Assoc Prof.
[/TD]
[/TR]
[TR]
[TD] Assoc Prof.,
[/TD]
[TD]Assoc Prof.
[/TD]
[/TR]
[TR]
[TD] Assoc Prof.,
[/TD]
[TD]Assoc Prof.
[/TD]
[/TR]
[TR]
[TD]Assoc Prof.,
[/TD]
[TD]Assoc Prof.
[/TD]
[/TR]
[TR]
[TD]Assoc Prof.,
[/TD]
[TD]Assoc Prof.
[/TD]
[/TR]
[TR]
[TD]Assoc Prof.,
[/TD]
[TD]Assoc Prof.
[/TD]
[/TR]
[TR]
[TD]Assoc, Dean & Prof.
[/TD]
[TD]Assoc, Dean & Prof.
[/TD]
[/TR]
[TR]
[TD]Assoc, Dean & Prof.
[/TD]
[TD]Assoc, Dean & Prof.
[/TD]
[/TR]
[TR]
[TD]Assoc, Dean, Prof., and Dir.,
[/TD]
[TD]Assoc, Dean, Prof., and Dir.
[/TD]
[/TR]
[TR]
[TD]Assoc, Dir., Jt. Degree Applied Legal Theory & Analysis Prog.,
[/TD]
[TD]Assoc, Dir., Jt. Degree Applied Legal Theory & Analysis Prog.
[/TD]
[/TR]
[TR]
[TD]Assoc, Prof North- western
[/TD]
[TD]Assoc, Prof North- western
[/TD]
[/TR]
[TR]
[TD]Assoc, Prof. & Dir.,
[/TD]
[TD]Assoc, Prof. & Dir.
[/TD]
[/TR]
[TR]
[TD]Assoc, Prof. & Dir.,
[/TD]
[TD]Assoc, Prof. & Dir.
[/TD]
[/TR]
[TR]
[TD]Assoc, Prof.
[/TD]
[TD]Assoc, Prof.
[/TD]
[/TR]
[TR]
[TD]Assoc, Prof.
[/TD]
[TD]Assoc, Prof.
[/TD]
[/TR]
[TR]
[TD]Assoc, Prof.
[/TD]
[TD]Assoc, Prof.
[/TD]
[/TR]
[TR]
[TD]Assoc, Prof.
[/TD]
[TD]Assoc, Prof.
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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