Removing Consecutive Duplicates

Cubist

Well-known Member
Joined
Oct 5, 2023
Messages
2,135
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I'm looking for a formula solution that removes the consecutive duplicate characters - keeping only one instance. Note that the characters are case-sensitive. See examples.
Book2
AB
1FromTo
2MississipiMisisipi
3RollerRoler
4ExcellentExcelent
5Mamma MiaMama Mia
6MmmmhmMmhm
7BelLairBelLair
Sheet4
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
This came to my mind (but I guess it is really complicated - but you are brilliant at making things easier):

Excel Formula:
=LET(split,CODE(MID(A2,SEQUENCE(LEN(A2)),1)),duplicates,IFERROR(split-(--(INDEX(split,SEQUENCE(ROWS(split)))=INDEX(split,SEQUENCE(ROWS(split),,2)))*split),CODE(RIGHT(A2,1))),filter,FILTER(duplicates,duplicates<>0),CONCAT(CHAR(filter)))
 
Upvote 0
One more option:

Excel Formula:
MAP(A2:A7,LAMBDA(c,LET(a,CODE(MID(c,SEQUENCE(LEN(c)),1)),b,a=DROP(VSTACK(a,""),1),CONCAT(CHAR(FILTER(a,b=FALSE))))))
 
Upvote 0
This came to my mind (but I guess it is really complicated - but you are brilliant at making things easier):
I appreciate the sentiment. I mostly learn from people on here and experiment with Excel. I can't claim to be brilliant.
 
Upvote 0
@shaowu459
Great solution. I'm making a minor change ROW() to SEQUENCE(LEN()) for more robust but works great.
Excel Formula:
=REDUCE(,MID(A2,SEQUENCE(LEN(A2)),1),LAMBDA(x,y,x&IF(EXACT(y,RIGHT(x)),,y)))
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,080
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