Private sub Calculate

aBcdcg

New Member
Joined
Oct 24, 2018
Messages
12
Hello,

I've next code, working well. De code will look in cell 'Database!B9' Iwant to expand the code, so it will look in cel 'Database!B9 or 'Database!B10'.

How do I expand this code?

THANKS!!


Code:
[CODE=vba]Private Sub Worksheet_Calculate()

   Sheets("A100").Visible = True
   Sheets("B200").Visible = True
   Sheets("C300").Visible = True

   Sheets("D400").Visible = True



   Select Case Worksheets("Database").Range("B9").Value
      Case Is = "1", "2"
         Sheets("A100").Visible = False
         Sheets("B200").Visible = False
         Sheets("C300").Visible = False

      Case "3", "4", "7", "8"
         Sheets("B200").Visible = False
         Sheets("C300").Visible = False
     
      Case "13", "14"

         Sheets("A100").Visible = False
         Sheets("D400").Visible = False
      End Select

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
like so?

VBA Code:
Private Sub Worksheet_Calculate()

    Sheets("A100").Visible = True
    Sheets("B200").Visible = True
    Sheets("C300").Visible = True

    Sheets("D400").Visible = True
    HideSheets Worksheets("Database").Range("B9").Value
    HideSheets Worksheets("Database").Range("B10").Value
End Sub

Sub HideSheets(cellValue As String)
    Select Case cellValue
    Case Is = "1", "2"
        Sheets("A100").Visible = False
        Sheets("B200").Visible = False
        Sheets("C300").Visible = False
    Case "3", "4", "7", "8"
        Sheets("B200").Visible = False
        Sheets("C300").Visible = False
    Case "13", "14"
        Sheets("A100").Visible = False
        Sheets("D400").Visible = False
    End Select
End Sub
 
Upvote 0
like so?

VBA Code:
Private Sub Worksheet_Calculate()

    Sheets("A100").Visible = True
    Sheets("B200").Visible = True
    Sheets("C300").Visible = True

    Sheets("D400").Visible = True
    HideSheets Worksheets("Database").Range("B9").Value
    HideSheets Worksheets("Database").Range("B10").Value
End Sub

Sub HideSheets(cellValue As String)
    Select Case cellValue
    Case Is = "1", "2"
        Sheets("A100").Visible = False
        Sheets("B200").Visible = False
        Sheets("C300").Visible = False
    Case "3", "4", "7", "8"
        Sheets("B200").Visible = False
        Sheets("C300").Visible = False
    Case "13", "14"
        Sheets("A100").Visible = False
        Sheets("D400").Visible = False
    End Select
End Sub

I think that, in this solution, the sheets will be hide if there is a case in the cel Database!B9 and B10. So if Database!B9 = 3, sheet B200 will be delete, but also if Database!B10=3, the sheet B200 will be delete. So I had to make a solution to the code or make a extra step in Database!B10.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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