Help on Extracting numbers from a comma-delimited list in excel

wangzic3

New Member
Joined
Feb 24, 2019
Messages
1
I am trying to extract numbers from a comma delimited list using excel function/or VBA code
The data looks like this:
1,55,,Private Information #1 for UB,After 56 seconds, your private estimate is that the final value will be $51.19
If the above data are in cell A1, I want to retrieve UB in cell B1 and 56 in cell C1 and 51.19 in cell D1. So, only the last characters in 3rd filed and only numbers in the 5th and 6th comma-separated field are needed, and there will only be one number in the 5th and 6th field. For the 5th segment, the # will always be surrounded by the same text( i.e., After xxx seconds). For the 6th segment, it will always be the final characters, and they always follow a single $
I am not familiar with excel and would appreciate any help! Thanks in advance.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Based on your string in "A1" (noting your string have 2 commas together near the start) then try this for results in Range("B1:D1")
Code:
[COLOR="Navy"]Sub[/COLOR] MG24Feb42
[COLOR="Navy"]Dim[/COLOR] Sp [COLOR="Navy"]As[/COLOR] Variant, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] s [COLOR="Navy"]As[/COLOR] Variant
Sp = Split(Range("A1"), ",")
[COLOR="Navy"]For[/COLOR] n = 0 To UBound(Sp)
   [COLOR="Navy"]Select[/COLOR] [COLOR="Navy"]Case[/COLOR] n
        [COLOR="Navy"]Case[/COLOR] [COLOR="Navy"]Is[/COLOR] = 3: s = Split(Sp(n), " "): [B1] = s(UBound(s))
        [COLOR="Navy"]Case[/COLOR] [COLOR="Navy"]Is[/COLOR] = 4: s = Split(Sp(n), " ")
            [COLOR="Navy"]For[/COLOR] c = 0 To UBound(s)
                [COLOR="Navy"]If[/COLOR] IsNumeric(s(c)) [COLOR="Navy"]Then[/COLOR] [C1] = s(c)
            [COLOR="Navy"]Next[/COLOR] c
        [COLOR="Navy"]Case[/COLOR] [COLOR="Navy"]Is[/COLOR] = 5: s = Split(Sp(n), " "): [D1] = s(UBound(s))
    [COLOR="Navy"]End[/COLOR] Select
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Hi,

Your count/descriptions of commas do Not match your sample.
Also, there's No space after the comma ( UB,After ) and before "After", there are no spaces in between the 1st 3 commas and letters, might there be ?

Please show a few more possible samples and an accurate description.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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