1

I have the following text, and I'd like to pull the PO number. Sometimes it starts with the words PO, sometimes it doesn't. If it doesn't, then PO number will start with either 901 or 902.

PO or PO Number starts may start in the beginning, middle or at the end. There'll always be a space "delimter" in the beginning and/or at the end

sometexthere sometext 123 90112345 sometext
some text PO90199 sometexthere
some 90 1 901999999 sometext
sometexthere 902123456
sometexthere PO90212334
PO902101010 sometext here
9019394 sometext here

What I'd like to extract would be

90112345
PO90199
901999999
902123456
PO90212334
PO902101010
9019394
7
  • 2
    What version do you have? Commented Aug 17, 2022 at 15:53
  • Excel 365 but not the latest version. VSTACK etc is not available. LAMBDA, LET, TEXTJOIN I do have...let me know what functions you need, and I can check
    – David.L
    Commented Aug 17, 2022 at 15:55
  • TEXTSPLIT would be the best, but that is in the release with VSTACK. =LET(txt,TEXTSPLIT(A1," "),FiLTER(txt,ISNUMBER(MATCH(LEFT(txt,3),{"PO9","901","902"},0)))) But there are other ways to split on the space for version without TEXTSPLIT. Commented Aug 17, 2022 at 16:00
  • 1
    Don't have TEXTSPLIT...so I'd assume I'd be using FILTERXML as an alternative?
    – David.L
    Commented Aug 17, 2022 at 16:11
  • Yes that is a good alternate. Commented Aug 17, 2022 at 16:23

1 Answer 1

1

Use BYROW to iterate the column and FILTERXML to split the TEXT. Then use FILTER to return the correct item from the FILTERXML array:

=BYROW(A1:A7,LAMBDA(a,LET(txt,FILTERXML("<t><s>"&SUBSTITUTE(a," ","</s><s>")&"</s></t>","//s"),FILTER(txt,ISNUMBER(MATCH(LEFT(txt,3),{"PO9","901","902"},0))))))

enter image description here


Notes:

Note 1: FILTERXML is only available on the PC versions.

Note 2: Once TEXTSPLIT is introduced we can avoid the FILTERXML:

=BYROW(A1:A7,LAMBDA(a,LET(txt,TEXTSPLIT(a," "),FILTER(txt,ISNUMBER(MATCH(LEFT(txt,3),{"PO9","901","902"},0))))
7
  • Is there a limit to BYROW? Cause when I use A3:A243 it works, but when it becomes A244, it doesn't spill down.
    – David.L
    Commented Aug 17, 2022 at 16:58
  • I think it may be a data thing. I just tested with 400 rows and it worked just fine. Commented Aug 17, 2022 at 17:03
  • You are right!!! Upon using your formula, I was able to find an issue with our naming due to human error. In a situation where I have both a text as follow "some text here PO90199999 90291234", if I'd like to take priority on the PO first, how do I go about doing it?
    – David.L
    Commented Aug 17, 2022 at 17:04
  • On a second thought, is it possible to combined these POs into 1? so if there's multiple POs found (PO9, 901 902), have it put together with semicolon as the delimter. i.e. "some text here PO90199999 90291234" will result to be "PO90199999;90291234"
    – David.L
    Commented Aug 17, 2022 at 17:13
  • Wrap the FILTER part in TEXTJOIN Commented Aug 17, 2022 at 17:17

You must log in to answer this question.

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