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:
  1. CheckGloss = Workbooks(SecurityWBK).ActiveSheet.Cells(GlossRow, GlossCoupon).Value
  2.             CheckSummit = SummitCouponRate
  3.             If CheckGloss <> CheckSummit Then
  4.                 Script
  5.             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:
  1. Function SummitCouponRate() As Double
  2.     If Trim(Workbooks(SummitWBK).ActiveSheet.Cells(SummitRow, SumFixFloat).Value) = "FIX" Then
  3.         SummitCouponRate = Workbooks(SummitWBK).ActiveSheet.Cells(SummitRow, SumCouponorSpread).Value
  4.     Else
  5.         SummitCouponRate = (Workbooks(SummitWBK).ActiveSheet.Cells(SummitRow, SumCouponorSpread).Value / 100#) + Workbooks(SummitWBK).ActiveSheet.Cells(SummitRow, SumCurrentRate).Value
  6.     End If
  7. 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?