Is there a better way to extract data from a string?

HockeyDiablo

Board Regular
Joined
Apr 1, 2016
Messages
182
I am trying to extract random pricing data within a string. I have about 50 set prices for items within the string. Wondering if one of you excel geniuses on here can think of an easy solution? Here is the method I have came up with. Any ideas are welcome.



ABCDE
DescriptionLeft 10 CharsNumber ExtractedRight 10 Chars
1Steel White $599 Sears Craftsman Trolley 22 198 galv rollers Total $815eel White599 Sears Cra
25 yr Sp $130.00 cables 38 Keyless entry FREE LM Belt Drive 10yr War. $349.00 517 Total on CC5 yr Sp $130 cables 38

<tbody>
</tbody>
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
=MID(A19,1+FIND("$",A19,1),FIND(" ",MID(A19,FIND("$",A19,1),LEN(A19)))-2)

Assuming you have text in A19
 
Upvote 0
Extract each set of numbers to a column?

Is there a way to extract each and every numbering sequence in a string to its own individual column?






ABCDEFG
1Steel White $599 Sears Craftsman Trolley 22 198 galv rollers Total$81559922198815
25 yr Sp $130.00 cables 38 Keyless entry FREE LM Belt Drive 10yr War. $349.00 517 Total on CC51303810349517

<tbody>
</tbody>
 
Upvote 0
Re: Extract each set of numbers to a column?

Code:
Sub extractNumbers()

    Dim lastNum As Boolean
    Dim thisNum As Boolean
    Dim nextCol As Integer
    
    nextCol = 2


    For x = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        For y = 1 To Len(Cells(x, 1).Value)
            Select Case IsNumeric(Mid(Cells(x, 1).Value, y, 1))
                Case True
                    Debug.Print Mid(Cells(x, 1).Value, y, 1)
                    printVal = printVal & Mid(Cells(x, 1).Value, y, 1)
                    thisNum = True
                Case False
                    lastNum = thisNum
                    thisNum = False
            End Select
            
            If Mid(Cells(x, 1).Value, y, 1) = "." And lastNum = True Then
                thisNum = True
                printVal = printVal & Mid(Cells(x, 1).Value, y, 1)
            End If
            
            If thisNum = False And lastNum = True Then
                Cells(x, nextCol) = printVal
                nextCol = nextCol + 1
                printVal = ""
            End If
        Next y
        nextCol = 2
        printVal = ""
        lastNum = False
        thisNum = False
    Next x


End Sub

This worked for the sample data. Might need some more rigorous testing though. I had to add a bit of a workaround for periods in the data.
 
Upvote 0
Re: Extract each set of numbers to a column?

I have merged your two threads together.

In the future, please continue in the same thread (do not start a new thread on the same topic). Per forum rules, posts of a duplicate nature will be locked or deleted (rule #12 here: Forum Rules).
 
Upvote 0
Re: Extract each set of numbers to a column?

I have merged your two threads together.

In the future, please continue in the same thread (do not start a new thread on the same topic). Per forum rules, posts of a duplicate nature will be locked or deleted (rule #12 here: Forum Rules).

I believe one posting was in relation to extracting data 10 characters to the left and right of a numbered value;
and the other was simply how to extract numbers in a sequence from a string.

Could you please inform me of how those 2 posts are the same?
 
Upvote 0
Re: Extract each set of numbers to a column?

For left 10 chars and right 10 chars, you can use =Left(A2,10) and =Right(A2,10) functions.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,054
Latest member
juliecooper255

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