Need Warning Message for User Error

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
I want to issue a user warning message if they attempt to run a macro when on another tab in the workbook.

This works when a user is on the wrong tab:

Code:
Sub Intro()
  On Error GoTo ErrMsg
  If ActiveWorkbook.Worksheets("Outdoor - Baseline") Is ActiveSheet Then IntroUpdate.Show
ErrMsg:
MsgBox ("User must have Outdoor - Baseline selected."), , ".:User Error:."
End Sub

However, it shows the warning message when they are also on the right tab as well.

I don't want it to show the msg when it is on the correct tab.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try

Code:
Sub Intro()
  On Error GoTo ErrMsg
  If ActiveSheet.Name = "Outdoor - Baseline" Then
    IntroUpdate.Show
    Exit Sub
End If
ErrMsg:
MsgBox ("User must have Outdoor - Baseline selected."), , ".:User Error:."
End Sub
 
Upvote 0
Firstly your code isn't generating an error and secondly, even if it did, all of it will run because you are missing Exit Sub before ErrMsg:. Try:

Code:
Sub Intro()
    If ActiveSheet.Name = "Outdoor - Baseline" Then
        IntroUpdate.Show
    Else
        MsgBox ("User must have Outdoor - Baseline selected."), , ".:User Error:."
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,935
Members
449,480
Latest member
yesitisasport

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