Extracting numerical data from a text string

lewis1

Board Regular
Joined
Jul 20, 2009
Messages
81
Hi everyone,

I have text data in the single cell in the following format.

New Advice Requested 242.59 Target Bps, [ Quantity : 3,700, Bps : 0, Target Bps : 242.59 ]

<tbody>
</tbody>

I would like to extract the 3 data points in the [ ] brackets into adjacent cells if possible.

1. Quantity
2. Bps
3. Target Bps.

Any help would be greatly appreciated.

Kind regards,
Lewis.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
@Lewis1

One easy and quick way of doing this by using Text to Columns. This can be found in "Data" tab in excel sheet
 
Upvote 0
Hi Happy Raul,

Agree, that was my first thought. What divider would you use? note there are comma separators in the numbers as well.
 
Upvote 0
@Lewis,

Select the Text in the excel sheet. Click on Text to Columns. There are two options Demilited and Fixed Width.

Please Select Fixed Width

Wherever you need a divider, double click - a arrow appears

If you don't need a divider, double click on the arrow, the arrow disappears.

Click Finish
 
Upvote 0
I need the practice so here's a Regex solution:

Excel 2010
AB
1New Advice Requested 242.59 Target Bps, [ Quantity : 3,700, Bps : 0, Target Bps : 242.59 ]
2
3
4Quantity3700
5Bps0
6Target Bps242.59

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
B4=GetData($A$1,A4)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



Code:
Function GetData(RegStr As String, id As String) As Variant
Dim RegExp As Object
Dim allMatches As Object


Set RegExp = CreateObject("VBScript.RegExp")
With RegExp
        .IgnoreCase = True
        .Pattern = "\[ Quantity : (\d{1,3},\d{3}), Bps : (\d+), Target Bps : (\d+.?\d+) \]"
End With


Set allMatches = RegExp.Execute(RegStr)


Select Case LCase(id)
    Case "quantity"
        GetData = CLng(allMatches.Item(0).submatches.Item(0))
    Case "bps"
        GetData = CDbl(allMatches.Item(0).submatches.Item(1))
    Case "target bps"
        GetData = CDbl(allMatches.Item(0).submatches.Item(2))
    Case Else
        GetData = "No Match Found"
End Select


End Function
 
Upvote 0
Fill in B1, C1, D1 according to the table below, enter into B2 the formula, then drag it across to column D, and down:

=-LOOKUP(1,-MID($A2,FIND(B1&" : ",$A2)+LEN(B1)+3,{1,2,3,4,5,6,7,8,9,10}))

In the source text numbers separators have been changed, according to my (continental) system.
Excel Workbook
ABCD
1QuantityBpsTarget Bps
2New Advice Requested 242.59 Target Bps, [ Quantity : 3.700, Bps : 0, Target Bps : 242,59 ]37000242,59
Sheet
 
Upvote 0
Hi everyone,

I have text data in the single cell in the following format.

New Advice Requested 242.59 Target Bps, [ Quantity : 3,700, Bps : 0, Target Bps : 242.59 ]

<tbody>
</tbody>

I would like to extract the 3 data points in the [ ] brackets into adjacent cells if possible.

1. Quantity
2. Bps
3. Target Bps.

Any help would be greatly appreciated.

Kind regards,
Lewis.

Hi Lewis,

I'm not sure this is the BEST way to do it, but it does work. I tested it with some strings that were longer values and it is still working. You should be sure to check it against a few more of your records to make sure.

Note that the formula is different for each of B1, C1, D1. All can be dragged down to subsequent rows.

Excel 2010
ABCD
1New Advice Requested 242.59 Target Bps, [ Quantity : 3,700, Bps : 0, Target Bps : 242.59 ]3,7000242.59
2New Advice Requested 1235.62 Target Bps, [ Quantity : 15,200, Bps : 28, Target Bps : 1235.62 ]15,200281235.62

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet4

Worksheet Formulas
CellFormula
B1=MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,": ",CHAR(1),1))+2,(FIND(CHAR(1),SUBSTITUTE(A1,", ",CHAR(1),2),2))-(FIND(CHAR(1),SUBSTITUTE(A1,": ",CHAR(1),1)))-2)
C1=MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,": ",CHAR(1),2))+2,(FIND(CHAR(1),SUBSTITUTE(A1,", ",CHAR(1),3),2))-(FIND(CHAR(1),SUBSTITUTE(A1,": ",CHAR(1),2)))-2)
D1=MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,": ",CHAR(1),3))+2,(FIND(CHAR(1),SUBSTITUTE(A1," ]",CHAR(1),1))-2)-(FIND(CHAR(1),SUBSTITUTE(A1,": ",CHAR(1),3))))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Problem 2

On January 1,2011 you were given the following post dated checks

Check no


amount

Data on check

0683
1950

30.may.2011

0680
1300
28.feb.2011
0690
2800
30.aug.2011
0710
4000
30.nov.2011

<tbody>
</tbody>


Assume that the monthly interest rate is % 2

a) calculate the present value of each check.
b) Suppose you got only one check with a data of 30 June 2011 .if this check has the same present value as the four checks above, what is its amount?
 
Upvote 0
Peshraw - this is not related to the OP's question at all. This looks like a question from your FIN 200 course... it doesn't look related to excel at all.

Problem 2

On January 1,2011 you were given the following post dated checks

Check no
amountData on check
06831950
30.may.2011
0680130028.feb.2011
0690280030.aug.2011
0710400030.nov.2011

<tbody>
</tbody>


Assume that the monthly interest rate is % 2

a) calculate the present value of each check.
b) Suppose you got only one check with a data of 30 June 2011 .if this check has the same present value as the four checks above, what is its amount?
 
Upvote 0
Thanks very much everyone! I will dry run these solutions tomorrow and let you know how it goes!

Tx again!
 
Upvote 0

Forum statistics

Threads
1,216,384
Messages
6,130,309
Members
449,571
Latest member
Jay Zyller

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