How to find variable length/position text string in cell

hizzle

New Member
Joined
Apr 30, 2004
Messages
26
Can't quite figure this out.

I have a list of part numbers (about 20 characters, containing numbers, letters, symbols and spaces) and what I am trying to do is look for certain "codes" within each part number and put them in a separate column. The code does not always appear at the same position in the part number, nor is it always the same length.

For example, I am trying to take the part numbers
213241KRT : purplewidget
2355434634QCK yellowpencil
43GRVRD : bluephone

And for each part number I want to look and see if the cell contains the code "KRT" or "QCKT" or "GRVRD", and if so then put whichever code is contained in the part number in the column next to it.
I'm guessing this requires some kind of macro, but I haven't been able to find anything that quite works. Any ideas would be very helpful. Thank you! :)
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Are there only those 3 codes?
Book1
ABCD
1213241KRT : purplewidgetKRT
22355434634QCK yellowpencilQCK
343GRVRD : bluephoneGRVRD
4
Sheet4


Formula in C1 copied down column

=INDEX({"KRT","QCK","GRVRD"},MATCH(TRUE,INDEX(ISNUMBER(SEARCH({"KRT","QCK","GRVRD"},A1)),0),0))
 
Upvote 0
Does the code always start in the first position after the last number and end in the position before the first space?
 
Upvote 0
...if so (per my previous post), try:

Code:
=MID(A1,MATCH(10,--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))+1,SEARCH(" ",A1)-MATCH(10,--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)))

confirmed with CTRL+SHIFT+ENTER and copied down
Book13
ABCD
1213241KRT : purplewidgetKRT
22355434634QCK yellowpencilQCK
343GRVRD : bluephoneGRVRD
Sheet1


which is an adaptation of Barry's formula (y) from here:

http://www.mrexcel.com/board2/viewtopic.php?p=732194
 
Upvote 0
Alternative

Hizzle,

This formula seems to work as well:
Code:
=IF(ISERROR(FIND("KRT",A6)),IF(ISERROR(FIND("QCK",A6)),"GRVRD","QCK"),"KRT")

Not too sure if it has any constraints though.

Cheers,
Matt
 
Upvote 0
hizzle,

How many unique SKUs' substrings are we talking about looking for here? By that I don't mean how many rows to scan, but how many codes like "KRT", "QCKT" and "GRVRD" need to be looked for? Just these three; just a dozen or so; or hundreds; or thousands?
 
Upvote 0
Hi,

Maybe another option:

=LOOKUP(9.99999999999999E+307,FIND({"","KRT","QCK","GRVRD"},A1),({"","KRT","QCK","GRVRD"}))
 
Upvote 0
Thanks everyone!

In this case the "code" is not necessarily next to a space (or any particular character).
And in general I would be searching from thousands of product numbers. The number of codes I would be searching for would likely be around 10 or so.

I was trying to think about a way that was most flexible so I could easily add more "codes" to look for as the product numbers continue to grow by the hundreds...
Thanks!! :LOL:
 
Upvote 0
Just for clarification is the code and the description in the same cell?
 
Upvote 0
If you adapt Fairwind's formula as below then you can add codes as necessary in column E without changing the formula. Note that the column header in E1 and blank space in E2 must remain.

Also, you might have a problem if any of your codes is a subset of another e.g. ABC and ABCD
Book1
ABCDEF
1Part NumberCodeCodelist
2213241KRT : purplewidgetKRT
32355434634QCK yellowpencilQCKKRT
443GRVRD : bluephoneGRVRDQCK
543BARRY : bluephoneBARRYGRVRD
6BARRY
7
Sheet4


Formula in C2 copied down column

=LOOKUP(9.99999999999999E+307,FIND(OFFSET($E$2,,,COUNTA(E:E),),A2),OFFSET($E$2,,,COUNTA(E:E),))
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,970
Members
448,933
Latest member
Bluedbw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top