Results 1 to 6 of 6

Thread: Pop up Message

  1. #1
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,494
    Thanks
    135
    Thanked 7 Times in 7 Posts

    Pop up Message

    I have text "variance in Col A and values in Col D on several sheets. Where the value in Col D in the same row as the text "variance" is not equal to zero, then I want a message to advise where row number and sheet the variance is on

    I have written code to do this, but it tell me that there are variabnce in Col D when in fact they are zero

    Your assistance in resolving this is most appreciated

    Sub Variance_Message()

    HTML Code:
    Dim ws As Worksheet, r As Range, msg As String, ff As String
    For Each ws In Sheets
        Set r = ws.Columns("a").Find("Variance")
        If Not r Is Nothing Then
            ff = r.Address
            Do
                If (r.Offset(, 4).Value <> 0) Then
                               msg = msg & ws.Name & r.Address(0, 0)
                End If
                Set r = ws.Columns("a").FindNext(r)
            Loop Until ff = r.Address
        End If
    Next
    MsgBox IIf(Len(msg) > 0, msg, "No Variances Found")
    End Sub

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,772
    Thanks
    402
    Thanked 1,550 Times in 1,405 Posts
    Howard,

    Try this minor change:
    r.Offset(, 4).Value
    to
    Round(r.Offset(, 4).Value,0)

    Of course if your variance values have decimal places you'll have to adjust the 0 to what ever number of decimal places are significant, e.g. if your significant values are like .001, .103, etc then change the 0 to 3, etc.

    HTH
    Last edited by RetiredGeek; 2013-07-27 at 06:24.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,789
    Thanks
    138
    Thanked 705 Times in 639 Posts
    Howard,

    Try changing the offset to 3 to get the column D. An offset of 4 will put you in column E

    Code:
    Dim ws As Worksheet, r As Range, msg As String, ff As String
    For Each ws In Sheets
        Set r = ws.Columns("a").Find("Variance")
        If Not r Is Nothing Then
            ff = r.Address
            Do
                If r.Offset(, 3).Value <> 0 Then
                      msg = msg & ws.Name & r.Address(0, 0) & ", "
                End If
                Set r = ws.Columns("a").FindNext(r)
            Loop Until ff = r.Address
        End If
    Next
    MsgBox IIf(Len(msg) > 0, msg, "No Variances Found")
    Last edited by Maudibe; 2013-07-27 at 23:27.

  4. #4
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,494
    Thanks
    135
    Thanked 7 Times in 7 Posts
    Hi Retired Geek & Maudibe

    Thanks for the help. The offset must be , 3.

    I have incorporated the round functon as suggested by Retired Geek

    Regards

    Howard

  5. #5
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    3,188
    Thanks
    152
    Thanked 591 Times in 561 Posts
    Hi Howard

    As per RG's note, don't forget to set round to 2 if you are working in dollars and cents.
    (Good job you're not working in pounds, shillings and pence)

    zeddy

  6. #6
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,494
    Thanks
    135
    Thanked 7 Times in 7 Posts
    Hi Zeddy

    Thanks for the advice-I had rounded to 2 and it works perfectly

    Regards

    Howard

Posting Permissions

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