0

This just has me puzzled. Every cell in this list contains a substring that is delimited by exactly 4 dashes. What I want to do is be able to extract that string into its own column. The string is not necessarily in the same position from cell to cell.

#99760395  AP965-690-0-WE-00
#88908-789302  92WQ-50Y-0-N-900BD
6676549  9W7B-20W-0-N-00  SERVO
RZ2268461 TAO120-50-0-X-000 W/ AMPLIFIER
REF# BW309-8WV9-0-V-00

Below is the end result I wish to achieve:

AP965-690-0-WE-00
92WQ-50Y-0-N-900BD
9W7B-20W-0-N-00
TAO120-50-0-X-000
BW309-8WV9-0-V-00

I've played around with a combination of LEN, FIND, LEFT, RIGHT functions but can't seem to achieve my intended result.

1
  • The group always seems to appear after the first group of spaces. Find the first character after the first group of spaces. The string ends the character before the next space. If you need to verify, count hyphens in that string and test for count=4. If the target string isn't necessarily the second space-delimited segment, parse segments, test for 4 hyphens, if not true, move to the next segment.
    – fixer1234
    Dec 27, 2016 at 21:03

1 Answer 1

2

Here it seems that your data always appears after the first group of spaces so I think this function will work for you. The key here is the use of Mid function.

Screenshot

=TRIM(IFERROR(MID(TRIM(A2);FIND(" ";TRIM(A2));FIND(CHAR(1);SUBSTITUTE(TRIM(A2);" ";CHAR(1);2))-FIND(" ";TRIM(A2)));RIGHT(TRIM(A2);LEN(TRIM(A2))-FIND(CHAR(1);SUBSTITUTE(TRIM(A2);" ";CHAR(1);1)))))

It looks pretty confusing so here's a small breakdown.
Part1:

=RIGHT(TRIM(A2);LEN(TRIM(A2))-FIND(CHAR(1);SUBSTITUTE(TRIM(A2);CHAR(32);CHAR(1);1)))

This will find the 1st occurrence of the " " (we could also use Char(32) but its probably easier to follow this way.) Because of TRIM the first group of spaces will always have the length of 1 (one space). That's why we can use the first and second occurrences.

Part2:

=MID(TRIM(A2);FIND(" ";TRIM(A2));FIND(CHAR(1);SUBSTITUTE(TRIM(A2);" ";CHAR(1);2))-FIND(" ";TRIM(A2)))

Here we find the string starting from the 1st occurrence to the 2nd occurrence.
If there is no space to find as the 2nd occurrence then this will produce an error. That is why we combine it with Part1.

=Trim(IFERROR(PART2;PART1))

Mike

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .