Hiding &Unhiding Sheets based on cell value.

Zahid Marwat

New Member
Joined
Sep 19, 2015
Messages
31
Peace be with you!
I have 4 sheets in a workbook, namely: TA&DA, SanctionOrder, Officers, Employees.
I need sheet TA&DA and SanctionOrder to be unhide constantly, while one out of the sheets Officers and Employees should unhide based on value in sheet TA&DA cell C6, which contains Servants' (Officers & Employees) grades starting from 1 to 22.
If cell C6 of sheet TA&DA is greater than 16, then sheet of Officers should unhide, otherwise sheet Employees should uunhide.
Is there any way out?
Thanks in anticipation for consideration.

Zahid
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
try
Code:
Sub MM1()
If Sheets("TA&DA").Range("C6").Value > 16 Then
    Sheets("Employees").Visible = False
    Sheets("Officers").Visible = True
    Else: Sheets("Officers").Visible = False
        Sheets("Employees").Visible = True
End If
End Sub
 
Upvote 0
Thanks Sir. It had some problem with its first line i.e.

Sub MM1()

I changed the above first line with:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Now it works well. Any suggestions regarding this; will it create problem in future, pls.
 
Upvote 0
No, it should be fine, as long as the code is in the TA&DA sheet module
 
Upvote 0
Sir, there is an issue with the hiding & unhiding sheets. The value of cell C6 of TA&DA sheet is changed by formula (not manually) based on the servant name entered via userform.
If I click anywhere in TA&DA sheet, hiding & unhiding take place. Is there any way out of direct hiding & unhiding instead of clicking in the sheet.
 
Upvote 0
Change the first line from
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

to
Code:
Sub Worksheet_Calculate()
 
Upvote 0
Fantastic!
Sir, I need a message box on opening of the workbook to show value in cell P6 of Officer sheet or W20 of Establishment sheet (Both the cells have same value based on a formula.).
It is also for your kind information that a userform have already been set to auto open on opening of the workbook, code for is:

Private Sub Workbook_open ()
UserForm1.Show
End Sub

Any solution, please.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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