|
-
Jun 14th, 2006, 05:42 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] VBA Excel - Double Comparison failure
Hi,
I am trying to compare two values from different spreadsheets in a macro in Excel (Excel 2002, Visual Basic 6.3).
Most of the time the comparison works, but occasionally it decides two values are unequal, when they are equal
as far as I can see, and verify when stepping through the code in the Visual Basic Editor.
The code is as follows
VB Code:
CheckGloss = Workbooks(SecurityWBK).ActiveSheet.Cells(GlossRow, GlossCoupon).Value
CheckSummit = SummitCouponRate
If CheckGloss <> CheckSummit Then
Script
End If
CheckGloss and CheckSummit are declared as Doubles.
I resorted to using them as the code was failing on this comparison.
SummitCouponRate is a Function, as follows
VB Code:
Function SummitCouponRate() As Double
If Trim(Workbooks(SummitWBK).ActiveSheet.Cells(SummitRow, SumFixFloat).Value) = "FIX" Then
SummitCouponRate = Workbooks(SummitWBK).ActiveSheet.Cells(SummitRow, SumCouponorSpread).Value
Else
SummitCouponRate = (Workbooks(SummitWBK).ActiveSheet.Cells(SummitRow, SumCouponorSpread).Value / 100#) + Workbooks(SummitWBK).ActiveSheet.Cells(SummitRow, SumCurrentRate).Value
End If
End Function
On most occasions where CheckGloss is equal to CheckSummit they are working fine, it is just a few where they are being taken to be not equal.
CheckGloss is equal to 2.688
Workbooks(SummitWBK).ActiveSheet.Cells(SummitRow, SumCouponorSpread).Value is 4.5
Workbooks(SummitWBK).ActiveSheet.Cells(SummitRow, SumCurrentRate).Value is 2.643
I have run the math through a calculator, and the fallback of pencil and paper and I still get 2.688 for CheckSummit.
Does anyone have any ideas as to why this is happening, also what the solution is?
Signature Under Construction 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|