Extracting "non uniform" numbers from a string

BigGee

New Member
Joined
Sep 8, 2020
Messages
14
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,

I have tried to the best of my personal abilities (which is not as good as I had hoped) to try and solve this issue but I cant get a solution, but I am absolutely sure that it is not too complicated and therefore hope that someone can help me?
In the table below I want to extract into 2 adjacent columns a. the quantity and b. the description (ideally excluding anything after the description, in the example batch 2) . I have tried LEFT, RIGHT and MID but fallen foul of the fact that the no. of characters vary.
I have seen lots of clever things people have done in similar scenarios but havent really understood the concept so was hopeful someone might be able to help out?

Production Stage - 100 x Heater Relay
Production Stage - 100 x Heater Relay
Production Stage - 40 x MM Lite
Production Stage - 60 x PCM batch 2

Thanks in anticipation

Neil
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Is this about VBA? Then perhaps InStr function will help with the variances. Based on the 4 rows you show,
- use it to find "-" and add 1
- use Val with Mid will return only the numbers that follow
- find x and add 1
- then Mid again to get the rest
The problem would be how to strip off anything after the point you want, which isn't clear to me. An example of that is PCM and not PCM batch or PCM batch 2?
 
Upvote 0
T202301a.xlsm
BCD
1
2Production Stage - 100 x Heater Relay100 Heater Relay
3Production Stage - 60 x PCM batch 260 PCM batch 2
4
1d
Cell Formulas
RangeFormula
C2:C3C2=--MID(B2,FIND("-",B2)+2,3)
D2:D3D2=MID(B2,FIND("x",B2)+1,99)
 
Upvote 0
That is great thankyou. Only slight issue was that in the event that there is a qty of 1 (or a single digit) then it returns the x
 
Upvote 0
How about
Excel Formula:
=--SUBSTITUTE(MID(B2,FIND("-",B2)+2,3),"x","")
 
Upvote 0
or if numbers could be larger or smaller

T202301a.xlsm
BC
2Production Stage - 100 x Heater Relay100
3Production Stage - 60 x PCM batch 260
4Production Stage - 1 x PCM batch 21
5Production Stage - 100000 x PCM batch 2100,000
6
1d
Cell Formulas
RangeFormula
C2:C5C2=--MID(B2,FIND("-",B2)+2,LEN(B2)-33)
 
Upvote 0
Thank you ver
or if numbers could be larger or smaller

T202301a.xlsm
BC
2Production Stage - 100 x Heater Relay100
3Production Stage - 60 x PCM batch 260
4Production Stage - 1 x PCM batch 21
5Production Stage - 100000 x PCM batch 2100,000
6
1d
Cell Formulas
RangeFormula
C2:C5C2=--MID(B2,FIND("-",B2)+2,LEN(B2)-33)
thank you very much for this. It sort of works but I have come across a very strange scenario where it works on some fields but not on others. On the ones where it doesnt work, it sometimes, but not always, works if I edit the cell number and then edit it back to the original. Here is the examples of 2 cells - I know it might be something really obvious that I am missing or have done wrong but I can't spot it. The only thing that is unusual about what I am trying to do is that I was trying to run the formula on a "calculated" field - one taken from another location so the field had a formula in it - that didnt work so I copied the content of the field as a paste special as text - and like I say it worked in some but not all instances, even though I just dragged the formula down.

1673598815640.png
1673598848086.png
 
Upvote 0
What about this one?

23 01 13.xlsm
BC
1
2Production Stage - 100 x Heater Relay100
3Production Stage - 60 x PCM batch 260
4Production Stage - 1 x PCM batch 21
5Production Stage - 100000 x PCM batch 2100000
6Production Stage - 2500 x T&T sensor2500
Get num
Cell Formulas
RangeFormula
C2:C6C2=MID(B2,19,FIND(" x",B2)-19)+0
 
Upvote 0
Solution
Try using Formula Evaluate (Formulas Formula Evaluate) to review the formulas.
find shows the - at position 18 +2 means first number is at position 20 If the "normal" text has unit of 1 the len is 34, the text with 2500 is 37 less 33 means number is 4 characters. This requires text like your examples.
Note "sensor" is shorter than batch 2; consequently, use Peter's suggestion. N.B. The formula depends on the unique character "x" at the position shown.
You could build the formula to search for the position of a space after the first number.
This is easier with Excel 365.

T202301a.xlsm
ABCDE
1
2Production Stage - 100 x Heater Relay100100 Heater Relay
3Production Stage - 60 x PCM batch 26060 PCM batch 2
4Production Stage - 1 x PCM batch 211 PCM batch 2
5Production Stage - 100000 x PCM batch 2100,000100,000 PCM batch 2
6Production Stage - 2500 x PCM sensor2502,500 PCM sensor
7Production Stage - 2500 x sen#VALUE!2,500 sen
8Production Stage - 2500x sen#VALUE!#VALUE! sen
9Production Stage - 2500 y sen 929#VALUE!#VALUE!#VALUE!
10Production Stage - 2500 Excel 3652,500Excel 365
1d
Cell Formulas
RangeFormula
D2:D9D2=--MID(B2,20,FIND(" x",B2)-19)
E2:E9E2=MID(B2,FIND("x",B2)+1,99)
D10D10=--TEXTBEFORE(TEXTAFTER(B10," ",3)," ",1)
E10E10=TEXTAFTER(B10," ",4)
C2:C9C2=--MID(B2,FIND("-",B2)+2,LEN(B2)-33)
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,844
Members
449,051
Latest member
excelquestion515

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