Consulting

Results 1 to 10 of 10

Thread: VBA to Identify Negative Balances

  1. #1
    VBAX Regular golf4's Avatar
    Joined
    Jul 2004
    Location
    Salem, OR
    Posts
    54
    Location

    VBA to Identify Negative Balances

    Hi, everyone -

    Been too long since I've been back, but between work and other stuff going on, hard to get on....... SORRY!!!!!

    I did have a quick question: our finance manager requested that I help him "jazz" up some of his spreadsheets by adding some wav files. I've inserted one that did work for a time, but no longer works. It's supposed to identify negative financial balances in the cells in Column C:

    Private Sub Worksheet_Change(ByVal Target As Range) 
    If Intersect(Target, Range("c2:c200")) Is Nothing Then 
        Exit Sub 
    Else 
        If Intersect(Target, Range("c2:c200")) < 0 Then 
            Application.ScreenUpdating = True 
            DoEvents 
            ActiveSheet.Shapes("object 1.wav").Select 'dan msg' 
            Selection.Verb Verb:=xlPrimary 
         End If 
    End If 
    End Sub
    Can anyone see a problem within the code?


    Thanks for the help.

    Frank
    Last edited by Aussiebear; 04-27-2023 at 07:36 PM. Reason: Adjusted the code tags

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Frank,

    as its VBA and not VB Script I have changed your title, but VB Script can bring less people to help you.

    Remembering, VBA is a subset out of VB Script which in turn is a subset out of Visual Basic.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Any possibility that the WAV file has either changed location or no longer exists?

  4. #4
    VBAX Regular golf4's Avatar
    Joined
    Jul 2004
    Location
    Salem, OR
    Posts
    54
    Location
    Thanks for the clarification, Carlos. I appreciate it.

    Frank

  5. #5
    VBAX Regular golf4's Avatar
    Joined
    Jul 2004
    Location
    Salem, OR
    Posts
    54
    Location
    Hi, Geekgirlau -
    Thanks for the response. I believe the wav file is still there. For example, I have the formula =A1-B1 in Cell C1. Cell C1 is the cell that I would be lookin at to see if "negative balance". If I enter "10" in Cell A1 and "50" in Cell B1, "-40" appears in Cell C1 but no wav. However, if I manually enter "-40" in Cell C1, the wav will kick off. This is driving me nuts!!!

  6. #6
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    The change event is not triggered when a formula recalculates. Your code needs to check for changes in the range that will be updated (ie column A and B) rather than column C.

  7. #7
    VBAX Regular golf4's Avatar
    Joined
    Jul 2004
    Location
    Salem, OR
    Posts
    54
    Location
    Thanks again. Can you give me an idea of how i can modify my existing code to accomplish what you're referring to?

  8. #8
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("a2:b200")) Is Nothing Then
        Exit Sub
        Else
        If Range("c" & Target.Row).Value < 0 Then
            Application.ScreenUpdating = True
            DoEvents
            ActiveSheet.Shapes("object 1.wav").Select 'dan msg'
           Selection.Verb Verb:=xlPrimary
       End If
        End If
    End Sub
    Last edited by Aussiebear; 04-27-2023 at 07:38 PM. Reason: Adjusted the code tags

  9. #9
    VBAX Regular golf4's Avatar
    Joined
    Jul 2004
    Location
    Salem, OR
    Posts
    54
    Location
    THANKS SO MUCH!!!!

    It works like a charm now. Really appreciate the help!!!

    Hope things are going great for ya "down under".

    Take care,

    Frank

  10. #10
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Golf4, my pleasure (and things are always great "down under"!)

    Don't forget to mark your thread as Solved.

Posting Permissions

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