VBA to Hide/Unhide Worksheets using Checkboxes (FormControl or ActiveX) and IF statement

michele_said

New Member
Joined
Dec 21, 2018
Messages
2
I have been trying to create a code that would hide/unhide certain worksheets based on the value formulated in Column R resulting from the Checkbox control value in Column Q indicated by TRUE or FALSE. See below-



COLUMN QCOLUMN R
Checkbox ()ControlFormulaSheet()Formulas contained in Column R cells
Checkbox 1FALSETRUESheet4ROW 38'=IF(OR(Q40=TRUE,Q41=TRUE),"TRUE","FALSE")
Checkbox 2FALSETRUESheet5ROW 39'=IF(OR(Q38=TRUE,Q40=TRUE,Q41=TRUE,Q42=TRUE),"TRUE","FALSE")
Checkbox 3TRUETRUESheet6ROW 40'=IF(OR(Q40=TRUE,Q41=TRUE),"TRUE","FALSE")
Checkbox 4FALSETRUESheet7ROW 41'=IF(OR(Q40=TRUE,Q41=TRUE),"TRUE","FALSE")
Checkbox 5FALSETRUESheet8ROW 42'=IF(OR(Q41=TRUE,Q42=TRUE,Q40=TRUE),"TRUE","FALSE")
FALSESheet9
Sheet15
Sheet16
Sheet17
ROW 43'=IF(OR(Q42=TRUE,Q41=TRUE),"TRUE","FALSE")
FALSESheet10ROW 44'=IF(OR(Q41=TRUE,Q42=TRUE,Q38=TRUE),"TRUE","FALSE")
FALSESheet11ROW 45'=IF(OR(Q41=TRUE,Q42=TRUE),"TRUE","FALSE")
FALSESheet12ROW 46'=IF(OR(Q41=TRUE,Q42=TRUE,Q38=TRUE),"TRUE","FALSE")
FALSESheet13
Sheet19
ROW 47'=IF(Q41=TRUE,"TRUE","FALSE")
FALSESheet14ROW 48'=IF(OR(Q41=TRUE,Q42=TRUE,Q38=TRUE),"TRUE","FALSE")
FALSESheet18ROW 49'=IF(OR(R45="TRUE",R46="TRUE",R48="TRUE"),"TRUE","FALSE")

<tbody>
</tbody>

I have tried both Form Control checkboxes, that result with the macro doing nothing, and ActiveX that results in an debugging error, ambiguous name error, or other. I'm starting to believe this may just not be possible.

PLEASE HELP ME :confused::):eek:
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Clicking a checkbox is easy and familiar to the user but here is a simple bit of code that is much simpler than using checkboxes
- test in a new workbook

After adding the code below, simply click on any cell in column Q (row 2 onwards) to click on or off
- use IF(Q2="P",value if TRUE,value if FALSE) in any formula as your test

Paste code into sheet module
(right click on sheet tab \ select View Code \ paste into code window \ {ALT}{F11} takes you go back to Excel)
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Row > 1 And Target.CountLarge = 1 And Target.Column = 17 Then
        Target.Font.Name = "Wingdings 2"
        If Target = "[COLOR=#ff0000][B]P[/B][/COLOR]" Then Target.ClearContents Else Target = "[COLOR=#ff0000][B]P[/B][/COLOR]"
        Target.Offset(, 1).Activate
    End If
End Sub

alternative letters you may prefer O, P, Q, R
 
Last edited:
Upvote 0
Thank you for you help Yongle! However, I am trying to hide the corresponding worksheets based on the "Target". [Example using your code above - if Q2="P" then it would hide Sheet5, etc.]
 
Upvote 0
To hide a sheet the code is

Code:
Sheets("Sheet5").Visible = False

1. do you want code that hides (unhide special) sheets listed in column S based on value in column R?
2. are the sheets listed in Column S separated with {ALT}{Enter}?
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

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