Extract from cell dollar amounts that vary in position and length

slblanzy

New Member
Joined
Apr 19, 2006
Messages
39
I'm trying to extract dollar amounts from a cell. The dollar amounts are all formatted with a $ but are not all the same length after the $, e.g. $100, $1235, $25, etc. Also, the dollar amounts appear in different positions in the various text strings, e.g. $100 gift certificate, Spa package for $1235, Tickets for $25 seat, etc. Is this possible?

My data looks like this (Column A is the text I'm working with, column B is the result I'm looking for):
<table>
<tbody>
<tr>
<td style="border: 1px solid #000000;">A</td>
<td style="border: 1px solid #000000;">B</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">Spa package for $1235</td>
<td style="border: 1px solid #000000;">$1235</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">$100 gift certificate</td>
<td style="border: 1px solid #000000;">$100</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">Tickets for $25 seat</td>
<td style="border: 1px solid #000000;">$25</td>
</tr>
</tbody>
</table>

I have access to either Win 7/Excel 2007 or MacOS 10.7/Excel 2011.
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
try

=MID(A2,FIND("$",A2),FIND(" ",A2&" ",FIND("$",A2))-FIND("$",A2))

If you need that text result to be converted to a number, just add 0
=MID(A2,FIND("$",A2),FIND(" ",A2&" ",FIND("$",A2))-FIND("$",A2))+0
 
Upvote 0
Give this formula a try...

=MID(A2,FIND("$",A2),FIND(" ",A2&" ",FIND("$",A2))-FIND("$",A2))
 
Upvote 0
VBA method


Code:
Sub Testt()
     
    Dim RegX As Object
    Dim Rng As Range
     
    Set RegX = CreateObject("vbscript.regexp")
     
    With RegX
        .Global = True
        .Pattern = "[^-0-9-$]"
    End With
     
    For Each Rng In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
        Rng.Offset(, 1) = RegX.Replace(Rng, "")
    Next Rng
     
End Sub
 
Upvote 0
This is one way:
Excel Workbook
AB
1Spa package for $1235$1235
2$100 gift certificate$100
3Tickets for $25 seat$25
Sheet1
Cell Formulas
RangeFormula
B1=TRIM(MID(A1,FIND("$",A1),IFERROR(FIND(" ",MID(A1,FIND("$",A1),LEN(A1))),LEN(A1))))

Hope that helps.
 
Upvote 0
Thanks everyone for replying. Jonmo1's formula, =MID(A2,FIND("$",A2),FIND(" ",A2&" ",FIND("$",A2))-FIND("$",A2))+0, was exactly what I needed.
 
Upvote 0
VBA method
Code:
Sub Testt()
     
    Dim RegX As Object
    Dim Rng As Range
     
    Set RegX = CreateObject("vbscript.regexp")
     
    With RegX
        .Global = True
        .Pattern = "[^-0-9-$]"
    End With
     
    For Each Rng In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
        Rng.Offset(, 1) = RegX.Replace(Rng, "")
    Next Rng
     
End Sub
A (really) different VBA method...
Code:
Sub Testt()
  Dim Addr As String
  Addr = "A2:A" & Cells(Rows.Count, "A").End(xlUp).Row
  Range(Addr).Offset(, 1) = Evaluate(Replace("IF(LEN(@),MID(@,FIND(""$"",@),FIND("" ""," & _
                                     "@&"" "",FIND(""$"",@))-FIND(""$"",@)))", "@", Addr))
End Sub
 
Upvote 0
Looks like I spoke a little too soon. After reviewing the results of Jonmo1's formula I realized I didn't pass along all the info I should have. Sorry about that. I only looked at a random sample of the text cells at first but now see that there are more of them with the below string where the dollar amount I'm looking for is between the "$" and "value" (again column A is the text I'm working with, column B is the result I'm looking for):
<p></p>
<table border="0">
<tbody>
<tr>
<td style="border: 1px solid #000000;">A</td>
<td style="border: 1px solid #000000;">B</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">3 $10 gift certificates ($30 value)</td>
<td style="border: 1px solid #000000;">$30</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">10 $15 gift certificates ($150 value)</td>
<td style="border: 1px solid #000000;">$150</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">200 commercial spots @ $15 each - $300 value</td>
<td style="border: 1px solid #000000;">$300</td>
</tr>
</tbody>
</table>

Yes, those cells are really copied directly from my data, new math and all. How they were using this to track and report on anything is a real head scratcher.
 
Upvote 0
See if this formula works for you...

=LOOKUP(E9+307,--LEFT(TRIM(RIGHT(SUBSTITUTE(A1,"$",REPT(" ",99)),99)),ROW(INDIRECT("1:99"))))
 
Upvote 0

Forum statistics

Threads
1,223,398
Messages
6,171,887
Members
452,429
Latest member
simransonu08

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