Help making a period appear only if there is a character in the cell.

TWTHOMAS

Board Regular
Joined
Mar 26, 2010
Messages
96
I am using this formula to get a middle initial from a name in column A

Names in Column A are like:

Thomas Dan J
Jones Susan
Ayers John B II

=TRIM(MID(SUBSTITUTE($A2," ",REPT(" ",LEN($A2))),((COLUMNS($A2:C2)-1)*LEN($A2))+1,LEN($A2)))&"."

I want to only have the period (".") appear if there is a middle initial.

Currently Susan Jones has a lone . in the middle initial field because she doesn't have a middle initial. Is there a way to make that period conditional based on if there is a character available?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
How about
=LEFT(TRIM(RIGHT(SUBSTITUTE(A1&" "," ",REPT(" ",255),2),255)),1) & REPT(".", 1<(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))
 
Upvote 0
=If(formula=".","",formula)

So in your case this should work:

=IF(TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&"."=".","",TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&".")
 
Upvote 0
Am sure there's a better way but try

=TRIM(MID(SUBSTITUTE($A2," ",REPT(" ",LEN($A2))),((COLUMNS($A2:C2)-1)*LEN($A2))+1,LEN($A2)))&if(LEN(A1)-LEN(SUBSTITUTE(A1," ","")) > 1,".","")
 
Upvote 0
How about
=LEFT(TRIM(RIGHT(SUBSTITUTE(A1&" "," ",REPT(" ",255),2),255)),1) & REPT(".", 1<(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))

This removes the period but also abbreviates full middle names to just an initial.

Can it be adjusted to not do that?
 
Upvote 0
=If(formula=".","",formula)

So in your case this should work:

=IF(TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&"."=".","",TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&".")



This one works perfectly but happens to reveal a new issue. When an employee has a full middle name prefered and we can't make it just an initial. Is there another adjustment to make it so if the middle name / initial is more that one character, it also doesn't have the period?

So the name

Jones David Joseph

ends up with Joseph in the column instead of Joseph. (with a period).

Or Thompson Jacob II is split so II ends up in the cell without a period.
 
Last edited:
Upvote 0
Its a bit long and maybe theres better way but seems to do what you require:


=IF(IF(LEN(TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&".")>2,TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1))),TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&".")=".","",IF(LEN(TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&".")>2,TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1))),TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&"."))
 
Upvote 0
Perfect!!
Thanks

Its a bit long and maybe theres better way but seems to do what you require:


=IF(IF(LEN(TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&".")>2,TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1))),TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&".")=".","",IF(LEN(TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&".")>2,TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1))),TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),((COLUMNS($A1:C1)-1)*LEN($A1))+1,LEN($A1)))&"."))
 
Upvote 0
Do you need to have the same (very long) formula for all columns?

Might something like this be acceptable?
For the moment I've assumed no more than 4 answer columns required.

Some more varied sample data & expected results might help if this isn't sufficient.

Excel Workbook
ABCDE
2Thomas Dan JThomasDanJ. 
3Jones SusanJonesSusan
4Ayers John B IIAyersJohnB.II
5Jones David JosephJonesDavidJoseph
Split Names
 
Upvote 0
These appear to work okay also. The only issues I see are two.

1. This still leaves a period in Column D when there is no middle initial or suffix. (i.e. Doe John)

2. This also shows #VALUE! where the formula appears and there is no name data but only in columns B and D.

Much smaller formulas though which is always easier to deal with.

Thanks!

Do you need to have the same (very long) formula for all columns?

Might something like this be acceptable?
For the moment I've assumed no more than 4 answer columns required.

Some more varied sample data & expected results might help if this isn't sufficient.

Split Names

ABCDE
2Thomas Dan JThomasDanJ.
3Jones SusanJonesSusan
4Ayers John B IIAyersJohnB.II
5Jones David JosephJonesDavidJoseph

<COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 133px"><COL style="WIDTH: 77px"><COL style="WIDTH: 69px"><COL style="WIDTH: 75px"><COL style="WIDTH: 45px"></COLGROUP><TBODY>
</TBODY>

Spreadsheet Formulas
CellFormula
B2=LEFT(A2,FIND(" ",A2)-1)
C2=TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",100)),100,100))
D2=TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",100)),200,100))&IF(MID(A2&" ",LEN(B2&C2)+4,1)=" ",".","")
E2=TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",100)),300,100))

<TBODY>
</TBODY>

<TBODY>
</TBODY>


Excel tables to the web >> Excel Jeanie HTML 4
 
Upvote 0

Forum statistics

Threads
1,216,120
Messages
6,128,948
Members
449,480
Latest member
yesitisasport

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