Hide/Unhide sheets with a checkbox on a mac

Sharper

New Member
Joined
Jan 19, 2018
Messages
5
I'm looking for a way to use checkboxes to hide/unhide sheets. I've found code for PCs, but they all use ActiveX. I'm on a Mac and don't have access to ActiveX. Is there a way to accomplish this on a Mac?

TIA
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
..
Untested because I don't have a MAC :

Code:
Option Explicit


Sub CheckSheeet()
    If ThisWorkbook.Worksheets(1).Shapes("Check Box 1").OLEFormat.Object.Value = 1 Then
       Sheets("Sheet3").Visible = False
    Else
       Sheets("Sheet3").Visible = True
    End If
End Sub


Paste in a Routine Module. Assign CheckBox1 to the above macro.
 
Upvote 0
..
Untested because I don't have a MAC :

Code:
Option Explicit


Sub CheckSheeet()
    If ThisWorkbook.Worksheets(1).Shapes("Check Box 1").OLEFormat.Object.Value = 1 Then
       Sheets("Sheet3").Visible = False
    Else
       Sheets("Sheet3").Visible = True
    End If
End Sub


Paste in a Routine Module. Assign CheckBox1 to the above macro.


Thanks so much. That worked!
 
Upvote 0
..
Untested because I don't have a MAC :

Code:
Option Explicit


Sub CheckSheeet()
    If ThisWorkbook.Worksheets(1).Shapes("Check Box 1").OLEFormat.Object.Value = 1 Then
       Sheets("Sheet3").Visible = False
    Else
       Sheets("Sheet3").Visible = True
    End If
End Sub


Paste in a Routine Module. Assign CheckBox1 to the above macro.


Now that this works for one check box. Is there a way to hand 50 or so sheets?

TIA
 
Upvote 0
.

This is one way ...

Well ... if you are wanting one checkbox to hide/unhide several sheets at once you can use this macro :

Code:
Sub ToggleHideUnhideDataSheets()


Application.ScreenUpdating = False
Dim wb As Workbook
Dim ShtNames() As Variant
Dim i As Integer


Set wb = ActiveWorkbook
ShtNames = Array("Sheet3", "Sheet5", "Sheet9")  '<<--- edit sheet names here. You can add or delete sheet names as well but have at least two for the array.


    For i = 0 To UBound(ShtNames)
        wb.Sheets(ShtNames(i)).Visible = Not wb.Sheets(ShtNames(i)).Visible
    Next i
    
Application.ScreenUpdating = True


End Sub

Then, if you had a second checkbox to control several other sheets, you could duplicate the above macro and edit the sheet names to required.
 
Last edited:
Upvote 0
.

This is one way ...

Well ... if you are wanting one checkbox to hide/unhide several sheets at once you can use this macro :

Code:
Sub ToggleHideUnhideDataSheets()


Application.ScreenUpdating = False
Dim wb As Workbook
Dim ShtNames() As Variant
Dim i As Integer


Set wb = ActiveWorkbook
ShtNames = Array("Sheet3", "Sheet5", "Sheet9")  '<<--- edit sheet names here. You can add or delete sheet names as well but have at least two for the array.


    For i = 0 To UBound(ShtNames)
        wb.Sheets(ShtNames(i)).Visible = Not wb.Sheets(ShtNames(i)).Visible
    Next i
    
Application.ScreenUpdating = True


End Sub

Then, if you had a second checkbox to control several other sheets, you could duplicate the above macro and edit the sheet names to required.


I actually need to have a one to one relationship. I plan on having 50 checkboxes and 50 sheets.
 
Upvote 0
.
Ok .. then try this :

Code:
Option Explicit


Sub CheckSht()


    If ThisWorkbook.Worksheets(1).Shapes("Check Box 1").OLEFormat.Object.Value = 1 Then
       Sheets("Sheet3").Visible = False
    Else
       Sheets("Sheet3").Visible = True
    End If
End Sub

For CheckBox1 name the sub Sub CheckSht1()
For Checkbox2 name the sub Sub CheckSht2()
etc.
etc.

Edit this portion to the sheet corresponding to the Checkbox :

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

Then for the next sheet :

Code:
Sheets("Sheet6").Visible = False
 Else
 Sheets("Sheet6").Visible = True
 
Upvote 0
.
Ok .. then try this :

Code:
Option Explicit


Sub CheckSht()


    If ThisWorkbook.Worksheets(1).Shapes("Check Box 1").OLEFormat.Object.Value = 1 Then
       Sheets("Sheet3").Visible = False
    Else
       Sheets("Sheet3").Visible = True
    End If
End Sub

For CheckBox1 name the sub Sub CheckSht1()
For Checkbox2 name the sub Sub CheckSht2()
etc.
etc.

Edit this portion to the sheet corresponding to the Checkbox :

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

Then for the next sheet :

Code:
Sheets("Sheet6").Visible = False
 Else
 Sheets("Sheet6").Visible = True


Perfect. Works. Thanks so much.
 
Upvote 0
Hi, I've used this code and it works for me, however, it jumps to the sheet that I've just unhidden.

Is there anything I cam do to prevent this and stay on the sheet with the option button?

Thanks in advance,
Sean

.

This is one way ...

Well ... if you are wanting one checkbox to hide/unhide several sheets at once you can use this macro :

Code:
Sub ToggleHideUnhideDataSheets()


Application.ScreenUpdating = False
Dim wb As Workbook
Dim ShtNames() As Variant
Dim i As Integer


Set wb = ActiveWorkbook
ShtNames = Array("Sheet3", "Sheet5", "Sheet9")  '<<--- edit sheet names here. You can add or delete sheet names as well but have at least two for the array.


    For i = 0 To UBound(ShtNames)
        wb.Sheets(ShtNames(i)).Visible = Not wb.Sheets(ShtNames(i)).Visible
    Next i
    
Application.ScreenUpdating = True


End Sub

Then, if you had a second checkbox to control several other sheets, you could duplicate the above macro and edit the sheet names to required.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,812
Members
449,048
Latest member
greyangel23

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