Remove text from string between parenthesis leaving only numbers

zipotontic

New Member
Joined
Mar 11, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello!
I have an inventory list with products of various units of measure (box, each, spool, etc). If it is more than 1, the total number of units is included in parenthesis at the end of the item name. So, for example, if it is a spool of 100 feet, it will show (100FT) or, if it is a box of 50, it will show (50/bx), etc.

What I am trying to achieve is a column that lists only the numeric values found between the parenthesis.

So far I have written two different formulas that extract the string between the parenthesis. However, there are issues with each. Formula 1 extracts the entire string in between the parenthesis, I cannot figure out how to modify/add to this formula so that it will remove the text and leave only the number. Formula 2 is long and clunky but it does the trick more or less. The issue is it creates a lot of work for me because I have to make sure I scan an entire list of thousands of products to be sure I have included all units of measure (so far I have only found box, spool, each). Also, occasionally there will be an item with some other random bit of information in parenthesis not related to the unit of measure and my formula will end up displaying that.

Formula #1:
=IFERROR(MID(LEFT(A2,FIND(")",A2)-1),FIND("(",A2)+1,LEN(A2)),"")

Formula #2:
IF(D16="SPOOL",MID(LEFT(A16,FIND("FT)",A16)-1),FIND("(",A16)+1,LEN(A16)),IF(D16="BOX",MID(LEFT(A16,FIND("/BX)",A16)-1),FIND("(",A16)+1,LEN(A16)),IF((ISNUMBER(SEARCH(")",A16))),RIGHT(TEXTBEFORE(A16, ")"),3),"")))

Thanks so much for the help!
 

Attachments

  • example 1.jpg
    example 1.jpg
    135.7 KB · Views: 35
  • example 2.jpg
    example 2.jpg
    136.4 KB · Views: 36

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Should be fairly straight forward if you're willing to drag a vba function call down this column. If not, hang on for a formula solution, but formulas are not my thing. I can see a code solution that would find the point where "(" begins and ")" ends and captures what's in between. If no leading parenthesis in the cell then nothing is returned by the function.
 
Upvote 1
Should be fairly straight forward if you're willing to drag a vba function call down this column. If not, hang on for a formula solution, but formulas are not my thing. I can see a code solution that would find the point where "(" begins and ")" ends and captures what's in between. If no leading parenthesis in the cell then nothing is returned by the function.

Thank you so much for the response. I have nothing against VBA except that I really have zero idea how to use it. 😖 So, unless you feel like giving me a detailed instructional and a line by line function, I’m not sure I’ll be able to pull it off. 😕
 
Upvote 0
I can write that but not tonight. Too late here.
You'd drag the formula down column B (?) based on your pic, starting at B2. It would pass the value of A2 to the function, which would work as I described. If you had "( " or ")" in a header row like A15 in your pic, then that might be an issue. Otherwise should be OK. The formula is nothing more than a simple function call.
 
Upvote 1
Try this:

Book1
ABCDE
1FORMULA #johnnyL
2#10 CABLE TIE MOUNT (100)100381321EACH
3Fuse Holder ATO/ATC Waterproof 374374EACH
41/4IN BLK FIRE RTRD SPLIT LOOM (50/BX)50177658BOX
51IN BLK FIRE RTRD SPLIT LOOM (50/BX)50174670BOX
64IN NYLON CABLE TIE BLACK (100)100203023BAG
75.7IN NYLON CABLE TIE BLACK (100)100203027BAG
88IN NYLON CABLE TIE BLACK (100)100203031BAG
911.8IN NYLON CABLE TIE BLACK (100)100203035BAG
101/8IN BLK HEATSHRINK 48IN 77818EACH
11ROTATING CABLECAP INSULATOR (PR) 20304EACH
1214/2 RED/YEL RND SAFETY WIRE (100FT)10092703SPOOL
1312/2 RED/YEL RND SAFETY WIRE (100FT)10078924SPOOL
14
Sheet1
Cell Formulas
RangeFormula
B2:B13B2=TEXTJOIN("",TRUE,IFERROR((MID( TEXTBEFORE(TEXTAFTER(A2, "("), ")"),ROW(INDIRECT("1:"&LEN( TEXTBEFORE(TEXTAFTER(A2, "("), ")") ))),1)*1),""))
 
Upvote 1
Welcome to the MrExcel board!

I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

I also suggest that you investigate XL2BB for providing sample data to make it easier for helpers.

thousands of products
Not sure how many thousands but you may need to be a little wary of using the suggested formula from post #5 since INDIRECT is a volatile function and may slow your sheet performance. However, @johnnyL couldn't that volatile structure be replace with a SEQUENCE function since it seems the OP has a version with that available?

Another possible negative to the formula would be if data like I have in row 12 below is possible as the formula would not pick up that number.

I have nothing against VBA except that I really have zero idea how to use it. 😖 So, unless you feel like giving me a detailed instructional
I do have a vba suggestion. I have assumed that the data is in column A and column B is available for the results.
Test with a copy of your workbook.

To implement ..
1. With your workbook active press Alt+F11 to bring up the vba window.
2. In the Visual Basic window use the menu to Insert|Module
3. Copy (you can use the icon at the top-right of the forum code window) and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Press Alt+F8 to bring up the Macro dialog
6. Select the GetNumbers macro & click ‘Run’
7. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

VBA Code:
Sub GetNumbers()
  Dim RX As Object
  Dim a As Variant, b As Variant
  Dim i As Long
 
  Set RX = CreateObject("VBScript.RegExp")
  RX.Pattern = "(\([^\d\)]*)(\d+)"
  With Range("A2", Range("A" & Rows.Count).End(xlUp))
    a = .Value
    ReDim b(1 To UBound(a), 1 To 1)
    For i = 1 To UBound(a)
      If RX.test(a(i, 1)) Then b(i, 1) = RX.Execute(a(i, 1))(0).SubMatches(1)
    Next i
    .Offset(, 1).Value = b
  End With
End Sub

My sample data (thanks to @johnnyL for the XL2BB sample data) & vba results:

zipotontic.xlsm
AB
1
2#10 CABLE TIE MOUNT (100)100
3Fuse Holder ATO/ATC Waterproof
41/4IN BLK FIRE RTRD SPLIT LOOM (50/BX)50
51IN BLK FIRE RTRD SPLIT LOOM (50/BX)50
64IN NYLON CABLE TIE BLACK (100)100
75.7IN NYLON CABLE TIE BLACK (100)100
88IN NYLON CABLE TIE BLACK (100)100
911.8IN NYLON CABLE TIE BLACK (100)100
101/8IN BLK HEATSHRINK 48IN
11ROTATING CABLECAP INSULATOR (PR)
12ROTATING CABLECAP INSULATOR (PR) (EACH 50)50
1314/2 RED/YEL RND SAFETY WIRE (100FT)100
1412/2 RED/YEL RND SAFETY WIRE (100FT)100
Sheet1
 
Upvote 1
Not sure how many thousands but you may need to be a little wary of using the suggested formula from post #5 since INDIRECT is a volatile function and may slow your sheet performance. However, @johnnyL couldn't that volatile structure be replace with a SEQUENCE function since it seems the OP has a version with that available?

Another possible negative to the formula would be if data like I have in row 12 below is possible as the formula would not pick up that number.

You are exactly right.

I stink at formulas so I just put together something that worked for the data provided. I totally missed the 'thousands' reference in the OP.
 
Upvote 1
If any number to be extracted is in a set of parentheses at the end of the data like all the samples, then this might be a formula approach.

zipotontic.xlsm
AB
1
2#10 CABLE TIE MOUNT (100)100
3Fuse Holder ATO/ATC Waterproof 
41/4IN BLK FIRE RTRD SPLIT LOOM (50/BX)50
51IN BLK FIRE RTRD SPLIT LOOM (50/BX)50
64IN NYLON CABLE TIE BLACK (100)100
75.7IN NYLON CABLE TIE BLACK (100)100
88IN NYLON CABLE TIE BLACK (100)100
911.8IN NYLON CABLE TIE BLACK (100)100
101/8IN BLK HEATSHRINK 48IN 
11ROTATING CABLECAP INSULATOR (PR) 
12ROTATING CABLECAP INSULATOR (PR) (EACH 50)50
1314/2 RED/YEL RND SAFETY WIRE (100FT)100
1412/2 RED/YEL RND SAFETY WIRE (100FT)100
Sheet2
Cell Formulas
RangeFormula
B2:B14B2=LET(t,TEXTAFTER(A2,"(",-1),IFERROR(CONCAT(IFERROR(MID(t,SEQUENCE(LEN(t)),1)+0,""))+0,""))
 
Upvote 1
Since we are dealing with hypotheticals, how would
ROTATING CABLECAP INSULATOR (EACH 50) (PR)
be handled?
 
Upvote 1
Since we are dealing with hypotheticals, how would
ROTATING CABLECAP INSULATOR (EACH 50) (PR)
be handled?
With the macro of course. :LOL:


.. otherwise possibly this I guess?

zipotontic.xlsm
AE
1
2#10 CABLE TIE MOUNT (100)100
3Fuse Holder ATO/ATC Waterproof 
911.8IN NYLON CABLE TIE BLACK (100)100
101/8IN BLK HEATSHRINK 48IN 
11ROTATING CABLECAP INSULATOR (PR) 
12ROTATING CABLECAP INSULATOR (PR) (EACH 50)50
1412/2 RED/YEL RND SAFETY WIRE (100FT)100
15 
16ROTATING CABLECAP INSULATOR (EACH 50) (PR)50
17(ROTATING) (CABLECAP) INSULATOR 45 (EACH 50) (PR)50
Sheet2
Cell Formulas
RangeFormula
E2:E3,E9:E12,E14:E17E2=LET(ch,MID(A2&"|",SEQUENCE(LEN(A2)+1),1),IFNA(TEXTBEFORE(TEXTAFTER(SUBSTITUTE(CONCAT(IF(ch="(",ch,IF(ch=")",ch,IFERROR(ch+0,"")))),"()",""),"("),")")+0,""))
 
Upvote 1
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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