Macro for extracting multiple decimal values from a single string

mlewand420

New Member
Joined
Aug 13, 2015
Messages
2
Hello All,

I have what I though was a simple problem however, its becoming quite a challenge with little or no precedence on the web for reference.

Ideally, I would love to have a macro (or vba) that will simply look at all of column "B" and extract the corresponding decimal value, percent value or numerical values to another same row column.

IS THIS EVEN Possible? :confused:

For Example:

Col ACol BCol CCol D
Row 2TEXTNeed 1st decimal number or number in string hereNeed 2nd decimal number or number in string here
Row 3Rates from .0008C to .0469E0.00080.0469
Row 4PROGRAM From 3267 To 326932673269
Row 5Percents from 49% to 87%4987

<tbody>
</tbody>












Additional Considerations:


1 - I have been successful in using the following FORMULA, however it work only for the first occurrence of a number. THE REAL TRICK IS GETTING THE SECOND NUMBER from starting from the RIGHT. =LOOKUP(9000000000+307,--LEFT(MID(B3,MIN(FIND({1,2,3,4,5,6,7,8,9,0},$B3&"1023456789")),999),ROW(INDIRECT("1:999"))))*0.0001 --> (Gives me | 0.0008 | above)

2 - The numbers may vary for example .009, 347, 8% etc... withing the text strings.

3 - Follow on calculations would then be installed into COL E to figure a variance.

4 - A MACRO or VBA script would be great but if you can create function to assist, that would be fine too.

5 - THIS WOULD BE HELPING LOTS OF PEOPLE SAVE TIME AND MONEY IF I COULD INTRODUCE THIS TOOL TO OUR PROCESS!

Please let me know if you need anything further from me to help with this puzzle.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this:

Code:
[FONT=lucida console][color=Royalblue]Sub[/color] a1092781a()
[i][color=seagreen]'https://www.mrexcel.com/forum/excel-questions/1092781-macro-extracting-multiple-decimal-values-single-string.html[/color][/i]

[color=Royalblue]Dim[/color] r [color=Royalblue]As[/color] Range
Application.ScreenUpdating = [color=Royalblue]False[/color]
[color=Royalblue]For[/color] [color=Royalblue]Each[/color] r [color=Royalblue]In[/color] Range([color=brown]"A2"[/color], Cells(Rows.count, [color=brown]"A"[/color]).[color=Royalblue]End[/color](xlUp))
    
    ary = Split(r, [color=brown]" "[/color])
    [color=Royalblue]For[/color] i = LBound(ary) [color=Royalblue]To[/color] UBound(ary)
        [color=Royalblue]If[/color] LCase(ary(i)) = [color=brown]"from"[/color] [color=Royalblue]Then[/color] r.Offset(, [color=crimson]1[/color]) = Val(ary(i + [color=crimson]1[/color]))
        [color=Royalblue]If[/color] LCase(ary(i)) = [color=brown]"to"[/color] [color=Royalblue]Then[/color] r.Offset(, [color=crimson]2[/color]) = Val(ary(i + [color=crimson]1[/color]))
    
    [color=Royalblue]Next[/color]

[color=Royalblue]Next[/color]
Application.ScreenUpdating = [color=Royalblue]True[/color]
[color=Royalblue]End[/color] [color=Royalblue]Sub[/color]
[/FONT]

Result:


Excel 2013 32 bit
A
B
C
1
TEXTNeed 1st decimal number or number in string hereNeed 2nd decimal number or number in string here
2
Rates from .0008C to .0469E
0,0008​
0,0469​
3
PROGRAM From 3267 To 3269
3267​
3269​
4
Percents from 49% to 87%
49​
87​
Sheet: Sheet1
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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