MsgBox Pops Up Multiple times if conditions are met

chason323

New Member
Joined
Sep 5, 2019
Messages
3
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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
Ah-ha! That did it. Thanks for your help.
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.
 
Upvote 0
You are welcome.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,756
Members
448,990
Latest member
Buzzlightyear

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top