Check diff  
Author Message
AndersBank





PostPosted: Visual Basic for Applications (VBA), Check diff Top

I have a sub that is called from a loop. It is supposed to check if the 
difference between two numbers is greater than a predefined errror 
tolarnance. However the difference between the two numbers shall only be 
checked if neither of them are zero. 

My problem is that no differences are deterected. My code is:

Dim dblLocalReturnDiff  As Double
   If rng4.Offset(l, 0) <> 0 And rng3.Offset(l, 0) <> 0 And rng4.Offset(l, 
0) <> rng3.Offset(l, 0) Then
      dblLocalReturnDiff = rng4.Offset(l, 0) - rng3.Offset(l, 0)
         If Abs(dblLocalReutrnDiff) > dblErrorMarginal Then
            MsgBox ("Local return skiljer sig at mellan portfoljen och 
benchmark!" & vbCrLf & "Kolla upp vad detta kan bero pa.")
            Err.Raise 600
         End If
   End If

I supsect that the problem is to be found in the first IF statement. What I 
want to say is that is neither one of the two values is zero and the two 
values are not equal to one another then I want to continue the check. I do 
not know how to write that so that it works. Please help me. Thanks very much!



Microsoft ISV Community Center Forums1  
 
 
BGim





PostPosted: Visual Basic for Applications (VBA), Check diff Top

Here is one solution to your problem. Use nested if's with the first if checking for 0.

if rng4.offset(0,1)<> 0 OR rng3.offset(0,1)<>0 then

if rng4.offset(0,1)<>rng3.offset(0,1) then

……

Endif

Endif