Force Msg Box on sheet selection

Ryan1996

Board Regular
Joined
Jun 4, 2018
Messages
55
Is there anyway i can force a msg box to appear when a specific sheet is selected? Is it also possible to include to option to run a specific macro from that box that appears too?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Yes and Yes:

We need exact details.

Like when what sheet or sheets are activated.
And run what script.
And what should the Message Box say?

Exact details will always help getting you a quick answer.
 
Last edited:
Upvote 0
I can adjust macro's. Just needed to know if possible and how.

When "Detailed assessment criteria" is activated

run macro "Scope_Removal"

Code:
Sub scope_removal()

Worksheets("Detailed assessment Criteria").Activate


Dim rng As Range, cell As Range
    Set rng = Range("G2:G1000")
        For Each cell In rng
        If cell = "No" Then cell.EntireRow.Hidden = True Else cell.EntireRow.Hidden = False
    Next cell
End Sub


Sub DefaultMsgBox()
MsgBox "Would you like to check that all out of scope controls are removed?"
End Sub

Yes = run macro then confirm macro has been run via message box.
No = Nothing, close message box.
 
Upvote 0
I asked the question because I thought you meant more then one sheet.
If you want something to happen when you activate 10 different sheets we would need to know what the script looks like.

We could say for example if sheet name is "Me" then Msgbox "Me" for example.
But when you say:
I can adjust macro's. Just needed to know if possible and how.

I'm not sure what to say.

Like is the script going to be the same for all sheets or always different.

If always different then you would have to use a script like this:
And each one may be different:

Right click on the sheet tab choose View code and put in this code.


Code:
Private Sub Worksheet_Activate()
'Modified  4/16/2019  9:56:14 AM  EDT
Cells(1, 1).Value = ActiveSheet.Name
End Sub


 
Upvote 0
If you wanted the same scipt to run in all sheets or a selected number of sheets you can use a script like this:

So you do not have to put a sheet activate script in all 10 or so of your sheet.

To install this script right click on any sheet tab.
Double click on "ThisWorkbook"

And enter this code:

Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'Modified  4/16/2019  10:06:35 AM  EDT
MsgBox "Hello You just activated sheet named  " & ActiveSheet.Name
End Sub
 
Upvote 0
The code you provided is just to activate said sheet/s.

I need the code for when that sheet (The one i mentioned) is clicked a message box will automatically pop up with the text (Mentioned above) and two options (Mentioned above)
 
Upvote 0
Did it myself..

Code:
Private Sub Worksheet_Activate()Cells(1, 1).Value = ActiveSheet.Name
Dim Answer As String
Dim MyNote As String
 
    MyNote = "Would you like to check controls have been removed?"
    Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "???")
    
If Answer = vbNo Then
        
    Else
        Call scope_removal
        MsgBox "Controls have been checked!"
    End If
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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