sjinvestigator
New Member
- Joined
- Aug 11, 2021
- Messages
- 9
- Office Version
- 2016
- Platform
- Windows
Hi all,
Hope you're doing well today. I've got a tricky problem involving parsing sub-strings that I've been struggling with for several days. I would be REALLY grateful if some kind soul could please help me get (re-)started or give me some guidance on how to approach this problem. I'd love even some simple pointers in the right direction as most of what I've tried has not worked well. I'm beginning to think this is impossible.
In a nutshell, I'm trying to write some VBA code that will loop through a column of cells that have text data similar to THIS:
* Margarine Wholesale (27), Margarine Retail (241), Margarine Retail (287), Margarine Bulk (1781) (CB28412)
* Margarine Wholesale (281), Margarine Retail (42), Margarine Retail (13), Margarine Bulk (27) (CB28412)
* Margarine Wholesale (19), Margarine Retail (281), Margarine Retail (411), Margarine Bulk (3814) (CB82474)
What I need to do is extract substrings that list the different types of margarine and their corresponding scancodes (CBxxxx). I want to just paste the results into another sheet.
So, for example, the result of processing the above would be a row that shows "CB28412" in Column A and "Margarine Wholesale (27), Margarine Retail (241), Margarine Retail (287), Margarine Bulk (1781), Margarine Wholesale (281), Margarine Retail (42), Margarine Retail (13), Margarine Bulk (27)" in column B.
Then the next row would have "CB82474" in column A and "Margarine Wholesale (19), Margarine Retail (281), Margarine Retail (411), Margarine Bulk (3814) (CB82474)" in column B.
Please see attached images and mini-sheets of an example of the data I am working with and expected results I want to get after running the macro on the Result tab.
On the plus side, each list of types of margarine starts with a star (*) and each scancode is in parenthesis at the end of the list of margarines. That's how I have been trying to identify each part of the substring. One the negative side, though, sometimes multiple lists of margarines apply to the same scancode and most entries have more than one scancode/list combo. I also sometimes find an extraneous line of text from our inventory system in between the lists of margarines of scancodes that need to be ignored. I only want to process the parts of the string that corresponds to lists starting with * and ending with a (CBxxxx) number
I've tried to make this as clear and representative of the data I'm working with as humanly possible without being too long or complex. I hope it's clear what I'm trying to do, but if you need any further information, please just let me know.
I want to offer my sincere thanks, in advance, to anyone who takes the time to look at this problem.
Thanks very much!!!!!
SJ
Mini sheet data sample:
Min sheet results sample:
Hope you're doing well today. I've got a tricky problem involving parsing sub-strings that I've been struggling with for several days. I would be REALLY grateful if some kind soul could please help me get (re-)started or give me some guidance on how to approach this problem. I'd love even some simple pointers in the right direction as most of what I've tried has not worked well. I'm beginning to think this is impossible.
In a nutshell, I'm trying to write some VBA code that will loop through a column of cells that have text data similar to THIS:
* Margarine Wholesale (27), Margarine Retail (241), Margarine Retail (287), Margarine Bulk (1781) (CB28412)
* Margarine Wholesale (281), Margarine Retail (42), Margarine Retail (13), Margarine Bulk (27) (CB28412)
* Margarine Wholesale (19), Margarine Retail (281), Margarine Retail (411), Margarine Bulk (3814) (CB82474)
What I need to do is extract substrings that list the different types of margarine and their corresponding scancodes (CBxxxx). I want to just paste the results into another sheet.
So, for example, the result of processing the above would be a row that shows "CB28412" in Column A and "Margarine Wholesale (27), Margarine Retail (241), Margarine Retail (287), Margarine Bulk (1781), Margarine Wholesale (281), Margarine Retail (42), Margarine Retail (13), Margarine Bulk (27)" in column B.
Then the next row would have "CB82474" in column A and "Margarine Wholesale (19), Margarine Retail (281), Margarine Retail (411), Margarine Bulk (3814) (CB82474)" in column B.
Please see attached images and mini-sheets of an example of the data I am working with and expected results I want to get after running the macro on the Result tab.
On the plus side, each list of types of margarine starts with a star (*) and each scancode is in parenthesis at the end of the list of margarines. That's how I have been trying to identify each part of the substring. One the negative side, though, sometimes multiple lists of margarines apply to the same scancode and most entries have more than one scancode/list combo. I also sometimes find an extraneous line of text from our inventory system in between the lists of margarines of scancodes that need to be ignored. I only want to process the parts of the string that corresponds to lists starting with * and ending with a (CBxxxx) number
I've tried to make this as clear and representative of the data I'm working with as humanly possible without being too long or complex. I hope it's clear what I'm trying to do, but if you need any further information, please just let me know.
I want to offer my sincere thanks, in advance, to anyone who takes the time to look at this problem.
Thanks very much!!!!!
SJ
Mini sheet data sample:
Scancode_Example.xlsx | ||||
---|---|---|---|---|
A | B | |||
1 | Month | Scancodes & Type | ||
2 | January | * Margarine Wholesale (27), Margarine Retail (241), Margarine Retail (287), Margarine Bulk (1781) (CB28412) * Margarine Wholesale (281), Margarine Retail (42), Margarine Retail (13), Margarine Bulk (27) (CB28412) * Margarine Wholesale (19), Margarine Retail (281), Margarine Retail (411), Margarine Bulk (3814) (CB82474) | ||
3 | February | * Margarine Wholesale (11), Margarine Retail (27), Margarine Retail (14), Margarine Bulk (15) (CB91254) * Margarine Wholesale (6), Margarine Retail (399), Margarine Retail (400), Margarine Bulk (51) (CB49185) | ||
4 | March | * Margarine Wholesale (1008), Margarine Retail (1009), Margarine Retail (1010), Margarine Bulk (1011) (CB11888) * Margarine Wholesale (227), Margarine Retail (228), Margarine Retail (229), Margarine Bulk (230) (CB11888) extraneous text sometimes present in my data * Margarine Wholesale (583), Margarine Retail (622), Margarine Retail (902), Margarine Bulk (114) (CB31122) more extraneous text * Margarine Wholesale (501), Margarine Retail (601), Margarine Retail (999), Margarine Bulk (293) (CB82474) * Margarine Wholesale (517), Margarine Retail (683), Margarine Retail (872), Margarine Bulk (336) (CB82474) | ||
Data |
Min sheet results sample:
Scancode_Example.xlsx | ||||
---|---|---|---|---|
A | B | |||
1 | Scancode | Applies To | ||
2 | CB28412 | Margarine Wholesale (27), Margarine Retail (241), Margarine Retail (287), Margarine Bulk (1781), Margarine Wholesale (281), Margarine Retail (42), Margarine Retail (13), Margarine Bulk (27) | ||
3 | CB82474 | Margarine Wholesale (19), Margarine Retail (281), Margarine Retail (411), Margarine Bulk (3814) | ||
4 | CB91254 | Margarine Wholesale (11), Margarine Retail (27), Margarine Retail (14), Margarine Bulk (15) | ||
5 | CB11888 | Margarine Wholesale (1008), Margarine Retail (1009), Margarine Retail (1010), Margarine Bulk (1011), Margarine Wholesale (227), Margarine Retail (228), Margarine Retail (229), Margarine Bulk (230) | ||
6 | CB31122 | Margarine Wholesale (583), Margarine Retail (622), Margarine Retail (902), Margarine Bulk (114) | ||
7 | CB82474 | Margarine Wholesale (501), Margarine Retail (601), Margarine Retail (999), Margarine Bulk (293), Margarine Wholesale (517), Margarine Retail (683), Margarine Retail (872), Margarine Bulk (336) | ||
Result |