Delimiter Dilemma

DeExcelerated

New Member
Joined
Mar 28, 2019
Messages
5
Hi All,

How do I add an "Oxford" comma?

From the example below, the formula
=SUBSTITUTE(REPLACE(REPT(", "&A2,A2<>"")&REPT(", "&B2,B2<>"")&REPT(", "&C2,C2<>"")&REPT(", "&D2,D2<>"")&REPT(", "&E2,E2<>"")&REPT(", "&F2,F2<>""),1,2,""),", "," and ",MAX(1,COUNTIF($A2:$F2,"?*")-1)) works but does not add a comma before the "and" delimiter on two or more values (as shown below):

Huggy Bear = Huggy Bear
Huggy Bear Mamma Bear = Huggy Bear and Mamma Bear
Huggy Bear Mamma Bear Brother Bear = Huggy Bear, Mamma Bear, and Brother Bear
Huggy Bear Mamma Bear Brother Bear Sister Bear = Huggy Bear, Mamma Bear, Brother Bear, and Sister Bear
Huggy Bear Mamma Bear Brother Bear Sister Bear Errant Bear = Huggy Bear, Mamma Bear, Brother Bear, Sister Bear, and Errant Bear
Huggy Bear Mamma Bear Brother Bear Sister Bear Errant Bear Baby Bear = Huggy Bear, Mamma Bear, Brother Bear, Sister Bear, Errant Bear, and Baby Bear

Any suggestions?


 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
=SUBSTITUTE(REPLACE(REPT(", "&A2,A2<>"")&REPT(", "&B2,B2<>"")&REPT(", "&C2,C2<>"")&REPT(", "&D2,D2<>"")&REPT(", "&E2,E2<>"")&REPT(", "&F2,F2<>""),1,2,""),", ",", and ",MAX(1,COUNTIF($A2:$F2,"?*")-1)) maybe?
 
Upvote 0
=SUBSTITUTE(REPLACE(REPT(", "&A2,A2<>"")&REPT(", "&B2,B2<>"")&REPT(", "&C2,C2<>"")&REPT(", "&D2,D2<>"")&REPT(", "&E2,E2<>"")&REPT(", "&F2,F2<>""),1,2,""),", ",", and ",MAX(1,COUNTIF($A2:$F2,"?*")-1)) maybe?

OMG. It's that simple? I've spent the last day and a half rearranging the COUNTIF part of the formula thinking it was the placement of the "and" delimiter and not just adding another "," at the end of the first string.

Oh, woe is me and my making a formula more convoluted than it needed to be.

THANK YOU
 
Upvote 0
WAIT!!

The comma delimiter can't be placed on two values only; it has to be three or more values:

Huggy Bear and Mamma Bear
Huggy Bear, Mamma Bear, and Brother Bear

The formula produces:

Huggy Bear, and Mamma Bear

Which is not considered an "Oxford" comma...

Sigh...
 
Upvote 0
you might add a further replace and find the very first one and delete that ?
 
Upvote 0
Hi,

Try it this way:


Book1
ABCDEFG
2Huggy BearHuggy Bear
3Huggy BearMamma BearHuggy Bear and Mamma Bear
4Huggy BearMamma BearBrother BearHuggy Bear, Mamma Bear, and Brother Bear
5Huggy BearMamma BearBrother BearSister BearHuggy Bear, Mamma Bear, Brother Bear, and Sister Bear
6Huggy BearMamma BearBrother BearSister BearErrant BearHuggy Bear, Mamma Bear, Brother Bear, Sister Bear, and Errant Bear
7Huggy BearMamma BearBrother BearSister BearErrant BearBaby BearHuggy Bear, Mamma Bear, Brother Bear, Sister Bear, Errant Bear, and Baby Bear
Sheet648
Cell Formulas
RangeFormula
G2=SUBSTITUTE(REPLACE(REPT(", "&A2,A2<>"")&REPT(", "&B2,B2<>"")&REPT(", "&C2,C2<>"")&REPT(", "&D2,D2<>"")&REPT(", "&E2,E2<>"")&REPT(", "&F2,F2<>""),1,2,""),", ",IF(COUNTA(A2:F2)<3," and ",", and "),MAX(1,COUNTA(A2:F2)-1))
 
Upvote 0
Thanks for the feedback, welcome to the forum.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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