Parsing comma/semicolon delimited line

John Yazou

New Member
Joined
Mar 17, 2002
Messages
49
Hi guys,
Am sure you guys can figure this out..

I have a string, which the # of comma delimited items varies..

eg. strLineBuffer = "A, B, C, D"

Is there some kind of function in excel vba that takes the string, and takes each word delimited with a comma and puts it in an array.

eg. MagicFunc (strLineBuffer)

returns an array that contains "A", "B", "C", "D"

Thanks...
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
found this code in one of my workbooks.. it should suit your needs; somebody from tech dept programmed it, i think...

Function Parse(strBody As String) As Variant

Dim strTemp As String
Dim strTempRpt As String
Dim intCntr As Integer
Dim arrRptNames() As String
On Error Resume Next

strTemp = strBody

Do
' Increase array size to handle each found report - cumulative.
ReDim Preserve arrRptNames(intCntr)
strTempRpt = strTemp

If InStr(strTempRpt, ",") > 0 Then

arrRptNames(intCntr) = Trim(Left(strTempRpt, _
InStr(strTempRpt, ",") - 1))
Else
arrRptNames(intCntr) = Trim(strTempRpt)
Parse = arrRptNames()
Exit Function
End If
intCntr = intCntr + 1
strTemp = Mid(strTemp, InStr(strTemp, ",") + 1)
Loop Until InStr(strTemp, ",") = 0
ReDim Preserve arrRptNames(intCntr)

Parse = arrRptNames()
End Function

so Parse("A, B, C, D") will return an array containing A, B, C, D...

Cheers,
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,208
Members
448,874
Latest member
Lancelots

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