简体   繁体   中英

Extracting a Number/Letter Code (C2, H3, W1 etc) from a text cell in Excel

I have an Excel list with course names and their number like this:

V3 Varikosis Masterclass

B3 Botulinumtoxin Premiumkurs, H2

M1 Mykologie Basiskurs [Digital], D1 Dermatoskopie Basiskurs [Digital]

B5 BTX Workshop (21.11.21) (sometimes there are random numbers that have nothing to do with the code like a date)

It's very messy since some people ordered two courses, so I can't just take the first two symbols from each cell. Is there a formula that finds and extracts a single letter and number combination from a string of text?

If you do not have any other cases eg max number of courses is 2 and comma and space is always the same it is rather straightforward.

=LEFT(A3,2)
=IFERROR(MID(A3,SEARCH(",",A3,1)+2,2),"")

在此处输入图像描述

You could try:

在此处输入图像描述

Formula in B1 :

=TRANSPOSE(FILTERXML("<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s[string-length()=2][translate(.,'ABCDEFGHIJKLMNIOPQRSTUVWXYZ','')*0=0][substring(., 2)*0=0]"))

What this does is:

  • FILTERXML() - Use this function to break down you input into an array of elements based on the space characters as delimiter, where we would use Xpath 1.0 expressions to filter out;
  • [string-length()=2] - Nodes of exactly two characters;
  • [string-length(translate(.,'ABCDEFGHIJKLMNIOPQRSTUVWXYZ',''))=1] - Nodes where uppercase alpha is translated to nothing we are left with a single character;
  • [substring(., 2)*0=0] - Finally we just need to make sure the 2nd character of the node is numeric.
  • TRANSPOSE() - With ms365 the above will return an array which I transposed in columns. However, even with Excel2013 and above there is a way to find these seperate nodes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM