4
1
I have a column in my datasheet that often contains a string that I want to place in another column. This string may occur multiple times and I want to place ALL instances of it into the other column. The column is delimited and I'd like to take the matching string and up to the delimiter.
An example:
Possessions
Fruit: apple, Car: Ford, Fruit: banana,
Car: Saturn,
Fruit: orange,
I'd like the next column to contain:
Fruit
Fruit: apple, Fruit: banana,
Fruit: orange,
It's easy enough to find the first instance of the string (new lines are for readability):
MID(A2,
FIND( *first instance of Fruit:* ),
FIND( *first comma after Fruit:* ) - FIND( *first instance of Fruit:* )
)
However I could encounter the string any number of times and want to catch all of them.
Also, the column is already a calculated field (a reference to another sheet) so I cannot use text to columns to split on the delimiter.
Any ideas on how to return all instances of the string? I'd rather avoid a VBA script if possible and use worksheet functions, but if it's not possible with functions I'm open to VBA.
Looks to me like you need a recursive (or perhaps in Excel parlance "circular") function that finds and instance, extracts it ,then concatenates it with the same search on the unmatched string until the entire string has been exhausted. VBA could handle this, but I'm not sure about native Excel cell-based functions... – David W – 2015-08-06T16:12:19.170
Hmmm...can you offer any more guidance on how formally the data is structured? That is, looking at your example, if I scan a string for the word "Fruit: " I can capture "apple," easily enough, but given the comma, how do I know to stop at "Car:" without inferring I know Car isn't a fruit? Guess I"m looking for formatting/delimiter rules... – David W – 2015-08-06T16:25:43.943
1There will always be a string delimiter at the start (like "Fruit:") and a character delimiter at the end (like ",") of what I want to capture. As such the delimiter will not appear inside the string I'm trying to capture, so it can be known that "Car:" shouldn't be returned because it's not between "Fruit:" and the first comma after "Fruit:" – Centimane – 2015-08-06T17:06:06.150
Thanks! That's very helpful. A regular expression-based solution would make this almost trivial, but it would be a VBA-based solution... – David W – 2015-08-06T17:11:28.743