Extract first numerical value to the left & right of a defined criteria from a string of text

HockeyDiablo

Board Regular
Joined
Apr 1, 2016
Messages
182
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]10 yr spring 399 rollers 188 sc 40 total 627 ck[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]sc $40 radio board $140 spring $103.80 total $283.80 ck [/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]same day 5 yr 299 cables 58 rollers 148 sc 40 545[/TD]
[/TR]
</tbody>[/TABLE]

Above are a few samples strings from Microsoft Excel that I need the extraction from, respectively in cells "A1", "A2", "A3"...

I have several items in the string and need to extract the pricing, but it could be to the left or the right and wont always carry a $ sign.

Example: I would like to select "sc" as the defined criteria and return the first numerical value to the left and right


Return: something like this

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]B[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]188, 40[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"], 40[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]148, 40[/TD]
[/TR]
</tbody>[/TABLE]

I could work with values in "B" and "C"
 
Last edited:
Runtime Error '9' Script out of range

Code:
Result(R, 1) = Result(R, 1) & ", " & Split(Trim(SC(1)))(0)

But it works when I use other data? Would a certain character throw this off??
That probably means you have the letters "sc" at the end of the text with no number following it. Change the line of code you posted to this (I marked the change in red) and see if it works correctly afterwards...

Result(R, 1) = Result(R, 1) & ", " & Split(Trim(SC(1)) & " ")(0)
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
That did it, but I am getting some alpha to return:

"alex trolley was disco'ed pitched struts and told her needed new springs to compensate for added weight. $399 10 year spring $129 strut $129 strut $40 sc total$697ck" Returns 40, total697ck

" having issues with light sockets again is using 100 watt lightbulbs recommended going down to 60 and trying rough sc bulbs would still like is to check it out ~vnl chris told him to stop using 100 watt bulbs the socket still worked but it was touchy. went over bb's and cables again still no go." Returns rough, bulbs
 
Last edited:
Upvote 0
That did it, but I am getting some alpha to return:

"alex trolley was disco'ed pitched struts and told her needed new springs to compensate for added weight. $399 10 year spring $129 strut $129 strut $40 sc total$697ck" Returns 40, total697ck

" having issues with light sockets again is using 100 watt lightbulbs recommended going down to 60 and trying rough sc bulbs would still like is to check it out ~vnl chris told him to stop using 100 watt bulbs the socket still worked but it was touchy. went over bb's and cables again still no go." Returns rough, bulbs
What should the answers be for the above two examples?
 
Upvote 0
Well come to think of it nothing.... if both equal alpha then Service Call "sc" charge would be 0$ and I can write that.

Its always my data. Thank you again sir.

Cheers
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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