Unhide worksheets with message box entry

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
I have some code, the purpose of which is to unhide a group of worksheets based on the data entry of one or two cells (H11 and H12). I am trying to enforce this by way of a message box entry. The problem I am encountering is that the only place I can find that it works (more or less) is in the Worksheet_Change event, and the problem with this is that every other line of code that causes a change in the worksheet will invoke the message box. I only want it to appear based on a change in range H11. If i try to to put it in the Worksheet_SelectionChange then it crashes (hard - stack overflows and other errors, including simply shutting down). I'd appreciate any advice here, or maybe there's another way to do it... The terms UnhideOpen, UnhideTSC, UnhideRoutine and UnhideDemo refer to the various worksheet groups. The code is here:
Code:
Application.ScreenUpdating = False
 
Dim purpose As String
purpose = Range("H11").Value
Dim Answer As String
 
If purpose = "" Then
    UnhideOpen 
End If
 
If purpose = "Annual PM or TSC" Or purpose = "Product Clinical Demo" Or _
purpose = "Installation" Or purpose = "Incoming Inspection" Then
    UnhideTSC 
End If
 
If purpose = "Clinical Support" Or purpose = "Emergency Service" Or _
purpose = "Upgrade or Update" Then
    Answer = MsgBox("Will a TSC be performed during this service visit?", vbYesNo + vbQuestion, "Perform TSC?")
        If Answer = vbYes Then
            UnhideTSC
        Else
            UnhideRoutine
        End If
End If
 
If purpose = "Conference or Commercial Demo" Or purpose = "Decommission" Then
    UnhideDemo
End If
 
Application.EnableEvents = False
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I havent looked too deeply into this, but just from looking quickly i would think that you could use a Worksheet_Change and start the entire procudure off with

if target.address="$H$11" then...

I would think at this point that the entire procedure would just be skipped if the change happened anywhere other than H11; thus getting rid of the issue of the unwanted msgbox.
 
Upvote 0
Code:
If Intersect(Target, Range("H11:H12') Is Nothing Then Exit Sub
Application.EnableEvents = False
'rest of your code
Application.EnableEvents = True

lenze
 
Upvote 0
Thanks Lenze, that did the trick! This will be the second or third time you pulled my bacon out! Cheers!
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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