PDA

View Full Version : Solved: VBA IF statement condition issue



boston4415
04-13-2009, 11:00 AM
I have a VB if statement that compares a report total (Range("ShareTotal")) to a running total (ReportTotal) – each total goes out 4 decimal places. They both match (1,703,874,448.7524) but the if statement is performing the “else” condition – as if they don’t match. My only guess is it has to do with going out 4 decimals. I tried a number of different data types and they all act like the two don’t match. . Any insight?



If Range("ShareTotal") = ReportTotal Then
MsgBox "Omni Shares ** Matches ** EARS Extract" & Chr(13) & Chr(13) & " " & Format(ReportTotal, "#,##0.0000; (#,##0.0000)"), vbInformation, "Share Reconciliation Report"
Else
MsgBox "Omni Shares ** Does Not Match ** EARS Extract" & Chr(13) & Chr(13) & " Difference: " & Format(ReportTotal - Range("ShareTotal").Value, "#,##0.0000; (#,##0.0000)"), vbCritical, "Share Reconciliation Report"
End If

Tommy
04-13-2009, 11:17 AM
Hi boston4415,

Welcome to vbax!

Try:
If round(Range("ShareTotal"),4) = round(ReportTotal,4) Then
This will round off the decimals to 4 places, sometimes there is a number way out there as in e-12

boston4415
04-13-2009, 11:29 AM
Thanks VBAX Mentor

Should have checked for that - assumed only 4 places - had a couple way out decimal amounts.