+ Reply to Thread
Results 1 to 3 of 3

conditional not finding correct results

  1. #1
    Craig
    Guest

    conditional not finding correct results

    I'm making a withholdings calculator which basically has to find which
    step the gross wages for the pay period are, for this i have

    sub FindStep()

    Dim R as Range
    Dim myTot as String
    Dim myAmt as String
    Dim myPerc as String
    Dim myBeg as String
    For Each R in Range("A2:A8")
    If myTot >= R.Value Then
    If myTot < R.Offset(0,1).Value Then
    myAmt = R.Offset(0,2).Value
    myPerc = R.Offset(0,3).Value
    myBeg = R.Value
    End If
    End If
    Next R

    End Sub

    now myTot is being set my an earlier equation that calculates some
    entries in a form, when i step through the code, i get things like
    myTot = "793.08", R.Value = 385 and R.Offset(0,1).Value = 1240 which as
    far as i can tell should meet the criteria I've set (I want it to meet
    the criteria, but the other variables never get set, so it crashes when
    they are used in the final calculation. Any idea what i'm doing wrong?


  2. #2
    NickHK
    Guest

    Re: conditional not finding correct results

    Craig,
    If the sample values are exactly correct, it looks like you are comparing
    the string "793.08" against the number 385 .
    If that is not what you intend, either use a numeric data type for MyTot or
    use CSng(MyTot) instead.

    NickHK

    "Craig" <Craig41Bl@gmail.com> wrote in message
    news:1153950745.264422.245280@p79g2000cwp.googlegroups.com...
    > I'm making a withholdings calculator which basically has to find which
    > step the gross wages for the pay period are, for this i have
    >
    > sub FindStep()
    >
    > Dim R as Range
    > Dim myTot as String
    > Dim myAmt as String
    > Dim myPerc as String
    > Dim myBeg as String
    > For Each R in Range("A2:A8")
    > If myTot >= R.Value Then
    > If myTot < R.Offset(0,1).Value Then
    > myAmt = R.Offset(0,2).Value
    > myPerc = R.Offset(0,3).Value
    > myBeg = R.Value
    > End If
    > End If
    > Next R
    >
    > End Sub
    >
    > now myTot is being set my an earlier equation that calculates some
    > entries in a form, when i step through the code, i get things like
    > myTot = "793.08", R.Value = 385 and R.Offset(0,1).Value = 1240 which as
    > far as i can tell should meet the criteria I've set (I want it to meet
    > the criteria, but the other variables never get set, so it crashes when
    > they are used in the final calculation. Any idea what i'm doing wrong?
    >




  3. #3
    Craig
    Guest

    Re: conditional not finding correct results

    that worked perfectly, thanks


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1