Consulting

Results 1 to 3 of 3

Thread: Solved: VBA IF statement condition issue

  1. #1

    Solved: VBA IF statement condition issue

    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

    Last edited by Aussiebear; 03-30-2023 at 03:42 PM. Reason: Added code tags

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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
    Last edited by Aussiebear; 03-30-2023 at 03:43 PM. Reason: adjusted the code tags

  3. #3
    Thanks VBAX Mentor

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •