Search For Double Characters and Place Character In-Between

Manfred

New Member
Joined
Jan 11, 2014
Messages
10
Is there a simple way to find all double characters in a string (of variable length) and place another character in-between them? I'm completely stumped!

eg. "MESSAGE" would become "MESXSAGE"
 
I've just tried that out - really nice! I'm still learning at the moment, I'm quite a long way off being able to write my own UDFs, but hopefully I'll get there one day!
Just stick at it and I'm sure you will get there. Remember that we all start off not even knowing what Excel or vba is. :)

Also note that the RegExp concept I used earlier could also be implemented as a UDF with the same features.

Rich (BB code):
Function SplitEm(s As String, Delim As String, Optional CheckCase As Boolean = False) As String
  With CreateObject("vbScript.RegExp")
    .Global = True
    .IgnoreCase = Not CheckCase
    .Pattern = "(.)(?=\1)"
    SplitEm = .Replace(s, "$1" & Delim)
  End With
End Function


Excel Workbook
ABCD
1MESSAGEMESXSAGEMES SAGEMES:-:SAGE
2CatCatCatCat
3MississippiMisXsisXsipXpiMis sis sip piMis:-:sis:-:sip:-:pi
4AaAaAAXaXAXaXAAaAaAA:-:a:-:A:-:a:-:A
5LlewellynLXlewelXlynLlewel lynL:-:lewel:-:lyn
Sheet1
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,216,523
Messages
6,131,171
Members
449,627
Latest member
ChrisNoMates

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