Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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" wrote in message
oups.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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default conditional not finding correct results

that worked perfectly, thanks

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting correct results for lookup? tgcali Excel Discussion (Misc queries) 4 July 15th 08 02:32 AM
what formulas will give correct results TUNGANA KURMA RAJU Excel Discussion (Misc queries) 0 February 26th 07 02:13 AM
Finding Correct Answer caldog Excel Worksheet Functions 0 November 25th 06 07:58 PM
SQL Query not returning correct results Stephen Excel Programming 0 July 20th 06 01:22 PM
Adding columns to get correct results Katherine[_6_] Excel Programming 1 August 19th 04 02:48 PM


All times are GMT +1. The time now is 01:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"