UDF or similar to extract currency amounts or numbers and symbols from text string

FreeRangeJ

New Member
Joined
Feb 7, 2013
Messages
40
i have a description column that contains the financial amounts that should be in other columns. I want to extract these amounts into helper columns, not the intended financial columns for validation purposes.

I've found a udf that almost works to pull all numbers from a text string but puts them in a number string with no grouping or symbols, another issue is that even though there are several decimal amounts in the string it pulls the last through or the only one through and decimals the whole resulting number string from that point

I've also found a udf that extracts the symbols into a symbol string

[TABLE="class: grid, width: 1600, align: center"]
<tbody>[TABLE="width: 1430"]
<colgroup><col><col><col><col></colgroup><tbody>[TR]
[TD]Order Detail[/TD]
[TD]UDF:Extract Numbers (as Number 0 decimals)[/TD]
[TD]UDF:Extract Numbers (as Number 2 decimals)[/TD]
[TD]UDF: Extract Symbols[/TD]
[/TR]
[TR]
[TD]Random Product 3 Qty: 4 Monthly: £7.00 Total Monthly: £28.00 Monthly Rollinng Tarrif national- 0.9bst allowance 3- 3.4mms [/TD]
[TD]3470028000933[/TD]
[TD]3470028000933.40[/TD]
[TD] : : £. : £. - . - . [/TD]
[/TR]
[TR]
[TD]23 johbfcvasebn 45 gtr ty65h mt 657[/TD]
[TD]234565657[/TD]
[TD]234565657.00[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]23 johbfcvasebn 45 gtr. ty65h mt 657[/TD]
[TD]2346[/TD]
[TD]2345.66[/TD]
[TD] .
[/TD]
[/TR]
</tbody>[/TABLE]
</tbody>[/TABLE]


so if you can almost do numbers and you can do symbols separately is there a way to do numbers fully combined with symbols and moreover is there a udf or similar to extract them (numbers and symbols) in the groups they appear in the string (using spaces as a delimiter?) so as in the first example:

3 : 4 : £7.00 : £28.00 - 0.9 3- 3.4

or in a string:

3:4:£7.00:£28.00-0.93-3.4

I don't fully understand the udfs i found, i can just see that the numbers one is kinda almost there, it reads like this:



Function ExtractNumber(rCell As Range, _
Optional Take_decimal As Boolean, Optional Take_negative As Boolean) As Double



Dim iCount As Integer, i As Integer, iLoop As Integer

Dim sText As String, strNeg As String, strDec As String

Dim lNum As String

Dim vVal, vVal2



sText = rCell

If Take_decimal = True And Take_negative = True Then

strNeg = "-" 'Negative Sign MUST be before 1st number.

strDec = "."

ElseIf Take_decimal = True And Take_negative = False Then

strNeg = vbNullString

strDec = "."

ElseIf Take_decimal = False And Take_negative = True Then

strNeg = "-"

strDec = vbNullString

End If

iLoop = Len(sText)



For iCount = iLoop To 1 Step -1

vVal = Mid(sText, iCount, 1)





If IsNumeric(vVal) Or vVal = strNeg Or vVal = strDec Then

i = i + 1

lNum = Mid(sText, iCount, 1) & lNum

If IsNumeric(lNum) Then

If CDbl(lNum) < 0 Then Exit For

Else

lNum = Replace(lNum, Left(lNum, 1), "", , 1)

End If

End If



If i = 1 And lNum <> vbNullString Then lNum = CDbl(Mid(lNum, 1, 1))

Next iCount





ExtractNumber = CDbl(lNum)



End Function

thanks in advance!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
This is a rough example:

[TABLE="class: grid, width: 1800, align: center"]
<tbody>[TABLE="width: 1968"]
<colgroup><col><col><col><col></colgroup><tbody>[TR]
[TD]ORDER DETAIL[/TD]
[TD]UDF Version (incl decimal error)[/TD]
[TD]Anticipated Version[/TD]
[TD]Ideal / Manual Version[/TD]
[/TR]
[TR]
[TD]Service Details Provide connection through Alpha site infrastructure, presented as an upgrade to Alpha's purchase from source. Product 1 Monthly Price £175 Installation / CPE £0 / Term 36 Months[/TD]
[TD="align: right"]0.1175036[/TD]
[TD]1 £175 / £0 / 36[/TD]
[TD]£175 £0[/TD]
[/TR]
[TR]
[TD]Managed service: Install £350 Monthly - £35.00 Terms - as per orginal contact EXP - 15/04/2015[/TD]
[TD="align: right"]35035.0015[/TD]
[TD]£350 - £35.00 - - 15/04/2015[/TD]
[TD]£350 £35.00[/TD]
[/TR]
[TR]
[TD]Upgrade from 10 to 30 with 100 scalability - Install: £1000 Monthl cost: £525 (as existing) Contract term: new 36 months[/TD]
[TD="align: right"]1030100100052540[/TD]
[TD]10 30 100 - : £1000 : £525 ( ) : 36[/TD]
[TD]£1000 £525[/TD]
[/TR]
[TR]
[TD]Increase from 30 to 60 for a temporary event. £200 one off cost. This has been raised in a ticket[/TD]
[TD="align: right"]3060200[/TD]
[TD]30 60 . £200 . [/TD]
[TD]£200[/TD]
[/TR]
[TR]
[TD]Upgrade to 60 (for a temporary event) Install: £200.00 Monthly: £50 Contract Term: 17/03/2015 to 16/04/2015[/TD]
[TD="align: right"]6020000501703200000000000[/TD]
[TD]60 ( ) : £200.00 : £50 : 17/03/2015 16/04/2015[/TD]
[TD]£200.00 £50[/TD]
[/TR]
[TR]
[TD]Temporary upgrade to 60M from 30 Install: £200.00 Monthly: £0.00 Contract Term: 30/11/2015[/TD]
[TD="align: right"]60302000000030100000[/TD]
[TD]60 30 : £200.00 : £0.00 : 30/11/2015[/TD]
[TD]£200.00 £0.00[/TD]
[/TR]
[TR]
[TD]Product 20 Install: £3,000.00 Monthly: £400.00 Managed Install: Included Monthly: Included Total Install: £3,000.00 Total Monthly: £400.00 Contract Term: 12 Months[/TD]
[TD="align: right"]20300000400003000000000000[/TD]
[TD]20 : £3,000.00 : £400.00 : : : £3,000.00 : £400.00 : 12[/TD]
[TD]£3,000.00 £400.00 £3000.00 £400.00[/TD]
[/TR]
[TR]
[TD]Services Size:10 s Install:£500 Monthly:£1000 Contract:12 Months Installed 09/09/08 Updated: 01/07/10 Size: 20[/TD]
[TD="align: right"]1050010001209090000000000[/TD]
[TD]:10 :£500 :£1000 :12 09/09/08 : 01/07/10 : 20[/TD]
[TD]£500 £1000[/TD]
[/TR]
[TR]
[TD]Retention of existing Product 20 for new monthly price of £700. This will replace the existing monthly charges of £1000 (ex. VAT). In addition, Monthly: £45.00 Backup Installaton £0.00 - Monthly: £0.00 Total Installation: £0.00 Total Monthly: £745.00 Contract: 36 Months [/TD]
[TD="align: right"]20700100045000000000000000000[/TD]
[TD]20 £700. £1000 ( . ) . , : £45.00 £0.00 - : £0.00 : £0.00 : £745.00 : 36[/TD]
[TD]£700 £1000 £45.00 £0.00 £0.00 £0.00 £745.00[/TD]
[/TR]
[TR]
[TD]Upgrade to 40 - New Monthly: £650.00 Term 36 months[/TD]
[TD="align: right"]406500036[/TD]
[TD]40 - : £650.00 36[/TD]
[TD]£650.00[/TD]
[/TR]
</tbody>[/TABLE]
</tbody>[/TABLE]
 
Upvote 0
well, it would have been, the table insert in post not coming through and can only insert image from url not from machine, inspired!
 
Upvote 0
does this layout make sense:

[TABLE="width: 2064"]
<colgroup><col><col><col><col></colgroup><tbody>[TR]
[TD]ORDER DETAIL
[/TD]
[TD]UDF Version (incl decimal error)[/TD]
[TD]Anticipated Version[/TD]
[TD]Ideal / Manual Version[/TD]
[/TR]
[TR]
[TD]Service Details Provide connection through Alpha site infrastructure, presented as an upgrade to Alpha's purchase from source. Product 1 Monthly Price £175 Installation / CPE £0 / Term 36 Months[/TD]
[TD]0.1175036[/TD]
[TD]1 £175 / £0 / 36[/TD]
[TD]£175 £0[/TD]
[/TR]
[TR]
[TD]Managed service: Install £350 Monthly - £35.00 Terms - as per orginal contact EXP - 15/04/2015[/TD]
[TD]35035.0015[/TD]
[TD]£350 - £35.00 - - 15/04/2015[/TD]
[TD]£350 £35.00[/TD]
[/TR]
[TR]
[TD]Upgrade from 10 to 30 with 100 scalability - Install: £1000 Monthl cost: £525 (as existing) Contract term: new 36 months[/TD]
[TD]1030100100052540[/TD]
[TD]10 30 100 - : £1000 : £525 ( ) : 36[/TD]
[TD]£1000 £525[/TD]
[/TR]
[TR]
[TD]Increase from 30 to 60 for a temporary event. £200 one off cost. This has been raised in a ticket[/TD]
[TD]3060200[/TD]
[TD]30 60 . £200 . [/TD]
[TD]£200[/TD]
[/TR]
[TR]
[TD]Upgrade to 60 (for a temporary event) Install: £200.00 Monthly: £50 Contract Term: 17/03/2015 to 16/04/2015[/TD]
[TD]6020000501703200000000000[/TD]
[TD]60 ( ) : £200.00 : £50 : 17/03/2015 16/04/2015[/TD]
[TD]£200.00 £50[/TD]
[/TR]
[TR]
[TD]Temporary upgrade to 60M from 30 Install: £200.00 Monthly: £0.00 Contract Term: 30/11/2015[/TD]
[TD]60302000000030100000[/TD]
[TD]60 30 : £200.00 : £0.00 : 30/11/2015[/TD]
[TD]£200.00 £0.00[/TD]
[/TR]
[TR]
[TD]Product 20 Install: £3,000.00 Monthly: £400.00 Managed Install: Included Monthly: Included Total Install: £3,000.00 Total Monthly: £400.00 Contract Term: 12 Months[/TD]
[TD]20300000400003000000000000[/TD]
[TD]20 : £3,000.00 : £400.00 : : : £3,000.00 : £400.00 : 12[/TD]
[TD]£3,000.00 £400.00 £3000.00 £400.00[/TD]
[/TR]
[TR]
[TD]Services Size:10 s Install:£500 Monthly:£1000 Contract:12 Months Installed 09/09/08 Updated: 01/07/10 Size: 20[/TD]
[TD]1050010001209090000000000[/TD]
[TD]:10 :£500 :£1000 :12 09/09/08 : 01/07/10 : 20[/TD]
[TD]£500 £1000[/TD]
[/TR]
[TR]
[TD]Retention of existing Product 20 for new monthly price of £700. This will replace the existing monthly charges of £1000 (ex. VAT). In addition, Monthly: £45.00 Backup Installaton £0.00 - Monthly: £0.00 Total Installation: £0.00 Total Monthly: £745.00 Contract: 36 Months [/TD]
[TD]20700100045000000000000000000[/TD]
[TD]20 £700. £1000 ( . ) . , : £45.00 £0.00 - : £0.00 : £0.00 : £745.00 : 36[/TD]
[TD]£700 £1000 £45.00 £0.00 £0.00 £0.00 £745.00[/TD]
[/TR]
[TR]
[TD]Upgrade to 40 - New Monthly: £650.00 Term 36 months[/TD]
[TD]406500036[/TD]
[TD]40 - : £650.00 36[/TD]
[TD]£650.00[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
If you have place for some helper columns you can use the formule below. Enter the formula in C1 then copy across and down, then enter the formula in B1 and copy down. You may have to concatenate more cells in B1, if there are more items to extract than 7.
Excel Workbook
ABCDEFGHI
1Service Details Provide connection through Alpha site infrastructure, presented as an upgrade to Alpha's purchase from source. Product 1 Monthly Price ?175 Installation / CPE ?0 / Term 36 Months?175 ?0?175?0
2Managed service: Install ?350 Monthly - ?35.00 Terms - as per orginal contact EXP - 15/04/2015?350 ?35.00?350?35.00
3Upgrade from 10 to 30 with 100 scalability - Install: ?1000 Monthl cost: ?525 (as existing) Contract term: new 36 months?1000 ?525 ?1000?525
4Increase from 30 to 60 for a temporary event. ?200 one off cost. This has been raised in a ticket?200 ?200
5Upgrade to 60 (for a temporary event) Install: ?200.00 Monthly: ?50 Contract Term: 17/03/2015 to 16/04/2015?200.00 ?50 ?200.00?50
6Temporary upgrade to 60M from 30 Install: ?200.00 Monthly: ?0.00 Contract Term: 30/11/2015?200.00 ?0.00 ?200.00?0.00
7Product 20 Install: ?3,000.00 Monthly: ?400.00 Managed Install: Included Monthly: Included Total Install: ?3,000.00 Total Monthly: ?400.00 Contract Term: 12 Months?3,000.00 ?400.00 ?3,000.00 ?400.00 ?3,000.00?400.00?3,000.00?400.00
8Services Size:10 s Install:?500 Monthly:?1000 Contract:12 Months Installed 09/09/08 Updated: 01/07/10 Size: 20?500 ?1000 ?500?1000
9Retention of existing Product 20 for new monthly price of ?700. This will replace the existing monthly charges of ?1000 (ex. VAT). In addition, Monthly: ?45.00 Backup Installaton ?0.00 - Monthly: ?0.00 Total Installation: ?0.00 Total Monthly: ?745.00 Contract: 36 Months?700. ?1000 ?45.00 ?0.00 ?0.00 ?0.00 ?745.00?700.?1000?45.00?0.00?0.00?0.00?745.00
10Upgrade to 40 - New Monthly: ?650.00 Term 36 months?650.00
Sheet
 
Last edited:
Upvote 0
Thanks Istvan

This looks great, have tested it on sample data with throw it into the full sheet shortly

I get the concatenation of B1 and B2, if you have time could you just quickly step through the Fx in C1

Thanks again
 
Upvote 0
Hi Istvan

Sorry for the tardiness, been sidelined. The it doesn't quite run but doesn't seem to error, but will pick this up tomorrow, new thread time, something that's more pressing is not quite working as i thought it might in my head, look our for IF AND Statement based on ranges
 
Upvote 0
I think this UDF will do what you want...
Code:
Function GetCur(S As String) As String
  Dim X As Long, Cur() As String
  Cur = Split(S, "£")
  For X = 1 To UBound(Cur)
    GetCur = GetCur & " £" & Format(Val(Cur(X)), "0.00")
  Next
  GetCur = Trim(GetCur)
End Function
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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