Results 1 to 6 of 6

Thread: MsgBox Pops Up Multiple times if conditions are met
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Sep 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default MsgBox Pops Up Multiple times if conditions are met

    Hey everyone,
    I am having some issues with a message box popping up 3 times for each scenario in the code below. I tried using Boolean values as explained in similar posts, but that just made the problem worse.
    Basically, there are two cells in question. I'd like for one message ("A") to pop up if the first cell reads "Expanded" and the other does not. And another, different message ("B") to pop up in the opposite scenario. Lastly, a third message will pop up in the case where both cells read "Expanded"

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
       Dim topcoattxt As String
       Dim primertxt As String
       
    topcoattxt = ActiveSheet.Range("B10").Text
    primertxt = ActiveSheet.Range("B11").Text
    
    
    If topcoattxt = "Expanded" And primertxt <> "Expanded" Then
    MsgBox ("A")
    End If
    If primertxt = "Expanded" And topcoattxt <> "Expanded" Then
    MsgBox ("B")
    End If
    If topcoattxt = "Expanded" And primertxt = "Expanded" Then
    MsgBox ("These C")
    End If
    End Sub
    Thanks

  2. #2
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,772
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: MsgBox Pops Up Multiple times if conditions are met

    Welcome to the Board!

    The way you have written this code, it will run any time ANY cell on the entire worksheet is manually updated.
    Is that what you really want? Or do you only want it to run when certain cells are updated?
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  3. #3
    New Member
    Join Date
    Sep 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: MsgBox Pops Up Multiple times if conditions are met

    well I'm locking the entire sheet, except or button that opens an Input box with 3 inputs. These user inputs are placed in cells B4,B5 and B6, and are used in calculations, multiple cells may or may not change every time the user inputs new values. So this was unintended, but still functions correctly. Unless there are adverse implications i am not aware of.

  4. #4
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,772
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: MsgBox Pops Up Multiple times if conditions are met

    These user inputs are placed in cells B4,B5 and B6
    How is this done? By VBA code?
    I believe updating each of those 3 cells is calling your code to run 3 times.

    If it is VBA code that is placing the values in V4, B5, and B6, it might be better to do away with the code you have above, and simply add to your existing code to cehck the values of B10 and B11 after updating cells B4, B5, and B6.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  5. #5
    New Member
    Join Date
    Sep 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: MsgBox Pops Up Multiple times if conditions are met

    Ah-ha! That did it. Thanks for your help.
    Quote Originally Posted by Joe4 View Post
    How is this done? By VBA code?
    I believe updating each of those 3 cells is calling your code to run 3 times.

    If it is VBA code that is placing the values in V4, B5, and B6, it might be better to do away with the code you have above, and simply add to your existing code to cehck the values of B10 and B11 after updating cells B4, B5, and B6.

  6. #6
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,772
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: MsgBox Pops Up Multiple times if conditions are met

    You are welcome.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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