Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Split up or delineate data

Hi,

Am Mon, 1 Feb 2021 12:11:05 -0800 (PST) schrieb Tatsujin:

For example, if

myStr = "ant,antique,art,bee,beautiful,bored,chores,dancin g,daytime"

then the output should be:

myStr2 = "--A--,ant,antique,art,--B--,bee, etc.."


then try:

Sub Test()
Dim myStr As String
Dim varData() As Variant
Dim re, match, matches, ptrn
Dim n As Long, i As Long

Set re = CreateObject("vbscript.regexp")
ptrn = "\w+"

myStr = "ant,antique,art,bee,beautiful,bored,chores,dancin g,daytime"
re.pattern = ptrn
re.IgnoreCase = False
re.Global = True
Set matches = re.Execute(myStr)
ReDim Preserve varData(n)
varData(n) = "---" & UCase(Left(matches(1), 1)) & "---"
n = n + 1
For i = 0 To matches.Count - 2
ReDim Preserve varData(n)
If Left(matches(i + 1), 1) = Left(matches(i), 1) Then
varData(n) = matches(i)
n = n + 1
Else
varData(n) = matches(i)
n = n + 1
ReDim Preserve varData(n)
varData(n) = "---" & UCase(Left(matches(i + 1), 1)) & "---"
n = n + 1
End If
Next
ReDim Preserve varData(n)
varData(n) = matches(matches.Count - 1)
myStr = Join(varData, ", ")
Range("A1") = myStr
End Sub


Regards
Claus B.
--
Windows10
Microsoft 365 for business
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
split data swati Excel Discussion (Misc queries) 3 August 7th 07 10:46 AM
I'm Lost... Bin? Delineate different processes with time samples William Elerding Excel Programming 5 August 10th 06 06:39 AM
Split data and copy surrounding data dee Excel Programming 5 July 19th 06 01:23 PM
Split data into new sheets bernard Excel Discussion (Misc queries) 4 January 4th 06 04:45 PM
how to split data into columns and arrange the resulting data jack Excel Discussion (Misc queries) 1 November 11th 05 11:20 PM


All times are GMT +1. The time now is 05:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"