String Parsing

airforceone

Board Regular
Joined
Feb 14, 2022
Messages
177
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
00000 TEMPLATE.xlsx
ABCD
1Copied EntryExpected Result
2Dog*Brown,White,Black,Dragon*Golden,Green,Red,Black,Panda*Red,Black,GreenDog*Brown,White,BlackDragon*Golden,Green,Red,BlackPanda*Red,Black,Green
Sheet1 (2)

As shown above I would like to parse the cell value for every "*" entry to arrive at the expected result, below is my somewhat working code :)
Number of Pet may go up as many as 8 sets, in the above example we have 3 Pet Sets ie. Dog, Dragon and Panda.
VBA Code:
Sub ListOfAnimals()
    Dim aPets() As String
    Dim iCTR As Long
    aPets = Split(Cells(2, 1), "*")
    For iCTR = LBound(aPets) To UBound(aPets)
        Debug.Print aPets(iCTR)
    Next
End Sub
 
You have placed the code in a different location to that suggested. Try it, as indicated, in a module in the workbook where it will be used, not in your personal macro workbook.
Oh My! Fault accepted! thanks mate, It's working now.
I'll try to find a remedy to parse it more, since there are 3 sets of animals in the string.
The code seems to just parse the first occurrence...
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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