VBA Msg Box only appear on single sheet

WillBurge

New Member
Joined
Jun 28, 2012
Messages
17
Hi - I have a series of combo boxes which change values in a table. I have multiple versions of the same combo box on different sheets, linked to the same cell.

On ONE of the sheets where these comboboxes reside I would like to display a warning message that when changed, the following tables have also changed.

I have the message box working fine on different choices, great.

However when the combobox is changed from another sheet, the message pops up. I only want to show this box on a single sheet. I have the message box running from a copy of the drop list on the sheet specied using the worksheet_calculate function in vba. Can anyone please advise o this?


Many thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
If I understand you correctly, I think you could check if the name of the current sheet the users on matches the name of the sheet you want the message displayed on and only show the message box if it is.

You could quickly accomplish that with something like:

Code:
If Application.ActiveSheet.Name = "Your_Sheet_Name" Then
MsgBox "Your Message"
End If
 
Upvote 0
That works perfectly, thank you kindly.

One more question....

I have 2 linked cells that change, which activate the message box. So the code looks like

If Cell a1 = 1 then msg "blah"
If Cell a1 = 2 then msg "blah"
If Cell a1 = 3 then msg "blah"

If Cell b1 = 1 then msg "blah"
If Cell b1 = 2 then msg "blah"
etc.

However, when just one of these values changes I have a message box appearing for both the true If statements, when I only want a message box for the cell that has changed. Is this possible at all?
 
Upvote 0
Glad it worked for you.

As for your second question I don't think there's any easy way to do that. One possible solution is in the 4th post here:

http://www.mrexcel.com/forum/showthread.php?41611-Trigger-macro-if-value-of-linked-cell-changes

If you take a quick look at the code example there I think that should do what you want.

You could use a slightly modified version of that code and perhaps change the worksheet_calculate event to something like this:

Code:
Private Sub Worksheet_Calculate() 

If Range("A1").Value <> MyA1 Then     
'A1 has changed... show the MsgBox only for this
MyA1 = Range("A1").Value
     
Select Case Range("A1").Value

Case 1
MsgBox "A1 changed to 1"

Case 2
MsgBox "A1 changed to 2"

Case 3
MsgBox "etc."

End Select
End If 

If Range("B1").Value <> MyB1 Then     
'B1 has changed... show the MsgBox only for this
MyB1 = Range("B1").Value
     
Select Case Range("B1").Value

Case 1
MsgBox "B1 changed to 1"

Case 2
MsgBox "B1 changed to 2"

Case 3
MsgBox "etc."

End Select
End If

End Sub

Then just make sure you declare both MyA1 and MyB1 in a general module as well as initializing both of them in the Workbook_Open event. Hopefully this should do the trick for you.
 
Upvote 0

Forum statistics

Threads
1,214,615
Messages
6,120,538
Members
448,970
Latest member
kennimack

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