Can someone help me with my VBA funtion

OK Here it goes:

I need to create a function that will pick up the last dollar amount in a string.  So for example, if I have the fiollowing string:

AJHY65 AAS JOHNSON AVE SLWX 3/13/06 259.22 59.90 3/08/05 6 YES

I need to return 59.90

Also each line is different with different values, the only real consistant thing is there will be two dollar amounts, which may or may not be the same, and  two dates

Can someone help me.  The more concise the better


Thanks,

jocasio
LVL 15
Juan OcasioApplication DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
If you're dollar amount is guaranteed to be the only thing with a period "." in it then:

Option Explicit

Private Sub Command1_Click()
    Dim data As String
    data = "AJHY65 AAS JOHNSON AVE SLWX 3/13/06 259.22 59.90 3/08/05 6 YES"
   
    Dim amount As String
    amount = getAmount(data)
    MsgBox amount
End Sub

Private Function getAmount(ByVal str As String) As String
    Dim vals As Variant
    vals = Split(str, " ")
    Dim i As Integer
    For i = UBound(vals) To LBound(vals) Step -1
        If InStr(vals(i), ".") > 0 Then
            getAmount = vals(i)
            Exit Function
        End If
    Next i
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Juan OcasioApplication DeveloperAuthor Commented:
That'll do it!

THanks

jocasio
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.