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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
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

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,154
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Give this formula a try...

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

vds1

Well-known Member
Joined
Oct 5, 2011
Messages
1,200
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

schielrn

Well-known Member
Joined
Apr 4, 2007
Messages
6,941
ADVERTISEMENT
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

slblanzy

New Member
Joined
Apr 19, 2006
Messages
39
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

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,154
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
ADVERTISEMENT
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

slblanzy

New Member
Joined
Apr 19, 2006
Messages
39
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

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,154
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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,195,855
Messages
6,011,974
Members
441,660
Latest member
Neela_Kattappa

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
Top