Extract numerical value after certain text

Lee85

New Member
Joined
Jan 19, 2021
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi

I am kinda new to this and I am hoping someone can help me
I would like to extract a numerical value after specific text
Example
Green 6 red 4
Green 8 blue 3
How would Ij extract just the 8 when the specific is Green and also is the word was Green and red

Hope this makes sense
 
Book1
ABCDEFGHIJKL
1After Nth SpaceSecond Situation
21234123
3Chl_Cpick 4 Chl_Mar 6Chl_Cpick4Chl_Mar6Chl_Cpick 4Chl_Mar 6Chl_Cpick4Chl_Mar6
4CrM_CLN 4 Chl_C/B 4CrM_CLN4Chl_C/B4CrM_CLN 4Chl_C/B 4CrM_CLN4Chl_C/B4
5ABS 4 Chl_C/B 4ABS4Chl_C/B4ABS 4Chl_C/B 4ABS4Chl_C/B4
6CrM_CLN 4 Hol 4CrM_CLN4Hol4CrM_CLN 4Hol 4CrM_CLN4Hol4
7
8
Sheet1
Cell Formulas
RangeFormula
H3:H6,B3:B6B3=LEFT(A3,FIND(" ",A3,1)-1)
C3:D6C3=MID($A3,FIND("~",SUBSTITUTE($A3," ","~",B$2))+1,FIND("~",SUBSTITUTE($A3," ","~",C$2))-FIND("~",SUBSTITUTE($A3," ","~",B$2))-1)
E3:E6E3=RIGHT(A3,LEN(A3)-FIND("~",SUBSTITUTE($A3," ","~",D$2)))
I3:I6I3=MID($G3,FIND("~",SUBSTITUTE($G3," ","~",H$2))+1,1)
J3:J6J3=MID($G3,FIND("~",SUBSTITUTE($G3," ","~",H$2))+2,FIND("~",SUBSTITUTE($G3," ","~",I$2))-FIND("~",SUBSTITUTE($G3," ","~",H$2))-2)
K3:K6K3=RIGHT($G3,LEN($G3)-FIND("~",SUBSTITUTE($G3," ","~",I$2)))
 
Upvote 0
Solution

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I see the Space before Numbers, Is it correct?
Yes the space before the numbers is correct
but after the 1st number there is no space
How would i go about by splitting them in that case
And how would i combine it with your 1st code

so if i had some appear like
Chl_Cpick 4Chl_Mar 6
CrM_CLN 8


sorry if i did'nt make it clear i am new to all this

Thanks for your help though
 
Upvote 0
just seen your second situation which works perfect for what i need

thank you so much
 
Upvote 0
One thing i totally forgot about is some of the numbers will be double so i could have
Chl_Cpick 2Chl_Mar 10 or just Chl_Mar 10 depending on what the day is your code works great if there single numbers but can it be adapted if they are are double or single

Thanks again
 
Upvote 0
At the first situation I change formula to Separated Both double number

NewRun.xlsm
ABCDEFGHIJK
1After Nth SpaceSecond Situation
21234123
3Chl_Cpick 10 Chl_Mar 10Chl_Cpick10Chl_Mar10Chl_Cpick 4Chl_Mar 6Chl_Cpick4Chl_Mar6
4CrM_CLN 4 Chl_C/B 4CrM_CLN4Chl_C/B4CrM_CLN 4Chl_C/B 10CrM_CLN4Chl_C/B10
5ABS 10 Chl_C/B 4ABS10Chl_C/B4ABS 4Chl_C/B 4ABS4Chl_C/B4
6CrM_CLN 10 Hol 4CrM_CLN10Hol4CrM_CLN 4Hol 4CrM_CLN4Hol4
Sheet1
Cell Formulas
RangeFormula
H3:H6,B3:B6B3=LEFT(A3,FIND(" ",A3,1)-1)
C3:D6C3=MID($A3,FIND("~",SUBSTITUTE($A3," ","~",B$2))+1,FIND("~",SUBSTITUTE($A3," ","~",C$2))-FIND("~",SUBSTITUTE($A3," ","~",B$2))-1)
E3:E6E3=TRIM(RIGHT(A3,LEN(A3)-FIND("~",SUBSTITUTE($A3," ","~",D$2))+1))
I3:I6I3=MID($G3,FIND("~",SUBSTITUTE($G3," ","~",H$2))+1,1)
J3:J6J3=MID($G3,FIND("~",SUBSTITUTE($G3," ","~",H$2))+2,FIND("~",SUBSTITUTE($G3," ","~",I$2))-FIND("~",SUBSTITUTE($G3," ","~",H$2))-2)
K3:K6K3=TRIM(RIGHT($G3,LEN($G3)-FIND("~",SUBSTITUTE($G3," ","~",I$2))+1))
 
Upvote 0
What if I just had CrM_CLN 10 along with the other mixed ones how would your formula work in this way both ways work when there is two sections to look at but can it be adapted to also look for the odd ones that would only have CrM_CLN 10 or something similar in the cell

After Nth SpaceSecond Situation
1​
2​
3​
4​
1​
2​
3​
Chl_Cpick 10 Chl_Mar 10Chl_Cpick10Chl_Mar10Chl_Cpick 4Chl_Mar 6Chl_Cpick4Chl_Mar6
CrM_CLN 4 Chl_C/B 4CrM_CLN4Chl_C/B4CrM_CLN 4Chl_C/B 10CrM_CLN4Chl_C/B10
ABS 10 Chl_C/B 4ABS10Chl_C/B4ABS 4Chl_C/B 4ABS4Chl_C/B4
CrM_CLN 10CrM_CLN
#VALUE!​
#VALUE!​
#VALUE!​
CrM_CLN 10CrM_CLN1
#VALUE!​
#VALUE!​

Thanks for your help on this
 
Upvote 0
Try this:
Book1
ABCDEFGHIJKL
1After Nth SpaceSecond Situation
21234123
3Chl_Cpick 10 Chl_Mar 10Chl_Cpick10Chl_Mar10Chl_Cpick 4Chl_Mar 6Chl_Cpick4Chl_Mar6
4CrM_CLN 4 Chl_C/B 4CrM_CLN4Chl_C/B4CrM_CLN 4Chl_C/B 10CrM_CLN4Chl_C/B10
5ABS 10 Chl_C/B 4ABS10Chl_C/B4ABS 4Chl_C/B 4ABS4Chl_C/B4
6CrM_CLN 10CrM_CLN  10CrM_CLN 4Hol 4CrM_CLN4Hol4
7
Sheet1
Cell Formulas
RangeFormula
H3:H6,B3:B6B3=LEFT(A3,FIND(" ",A3,1)-1)
C3:D6C3=IFERROR(MID($A3,FIND("~",SUBSTITUTE($A3," ","~",B$2))+1,FIND("~",SUBSTITUTE($A3," ","~",C$2))-FIND("~",SUBSTITUTE($A3," ","~",B$2))-1),"")
E3:E5E3=TRIM(RIGHT(A3,LEN(A3)-FIND("~",SUBSTITUTE($A3," ","~",D$2))+1))
E6E6=TRIM(RIGHT(A6,LEN(A6)-(LEN(B6)+IFERROR(LEN(C6),0)+IFERROR(LEN(D6),0))))
I3:I6I3=MID($G3,FIND("~",SUBSTITUTE($G3," ","~",H$2))+1,1)
J3:J6J3=MID($G3,FIND("~",SUBSTITUTE($G3," ","~",H$2))+2,FIND("~",SUBSTITUTE($G3," ","~",I$2))-FIND("~",SUBSTITUTE($G3," ","~",H$2))-2)
K3:K6K3=TRIM(RIGHT($G3,LEN($G3)-FIND("~",SUBSTITUTE($G3," ","~",I$2))+1))
 
Upvote 0
Hi Maabadi

This really helped alot but i now have another issue

We now get some that come through as 3.5 or something similar how could your code be adapted to caputre this as well
and is there a way to hide the #values

Book1.xls
ABCDE
1CrE_CRec 10CrE_CRec10#VALUE!######
2CrE_CRec 4 CrE_CLN 6CrE_CRec4 CrE_CLN6
3CrE_CRec 4.5 CrE_CLN 5.5CrE_CRec4..5 CrE_CLN5.5
Sheet1




hope this make sense

Regards

Lee
 
Upvote 0
This is very Complicated. You can Use UDF that I Created For you. If you has familiar with VBA it is very Easy. If Not Please Do Struction Step to Step.
1. At Excel Window Press ALT+F11 (this Open VBA window).
2. Go to Insert Menu & Select Module (Shortcut is ALT+I then ALt+M)
3. Then Paste this code at that windows appears:
VBA Code:
Public Function SplitText(pWorkRng As Range, pIsNumber As Long) As String
Dim xLen As Long, xStr1 As String, xStr2 As String, K As Long, i As Long
Dim Prt1 As String, Prt2 As String, Prt3 As String, Prt4 As String
xLen = Len(pWorkRng.Value)
xStr1 = VBA.Mid(pWorkRng.Value, 1, 1)
SplitText = xStr1
K = 1
For i = 2 To xLen
    If i > 2 Then xStr1 = VBA.Mid(pWorkRng.Value, i - 1, 1)
     xStr2 = VBA.Mid(pWorkRng.Value, i, 1)
    If VBA.IsNumeric(xStr2) = VBA.IsNumeric(xStr1) Or xStr2 = "." Or xStr1 = "." Then
        SplitText = SplitText + xStr2
    Else
      Select Case K
       Case 1
       Prt1 = SplitText
       Case 2
       Prt2 = SplitText
       Case 3
       Prt3 = SplitText
      
     End Select
       K = K + 1
       SplitText = VBA.Mid(pWorkRng.Value, i, 1)
    End If
Next i
Prt4 = SplitText
Select Case pIsNumber
       Case 1
       SplitText = Trim(Prt1)
       Case 2
       SplitText = Trim(Prt2)
       Case 3
       SplitText = Trim(Prt3)
       Case 4
       SplitText = Trim(Prt4)
     End Select
End Function
4. Close VBA window and then Save as Your file as Macro-Enabled Workbook (.xlsm)
5. Now your function is ready.
6. input in each cell =SplitText(
7.Select your Source Cell or type address for fist item
8. Input Part number that you want extract (from 1 to 4) Based your Data
9. Close Pranthesis and Press Enter

Example:

Excel Formula:
=SplitText(A3,1)
OR
Excel Formula:
=SplitText(A3,2)
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,982
Members
449,201
Latest member
Lunzwe73

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