VBA: If sheet is visible then

pplstuff

Well-known Member
Joined
Mar 9, 2012
Messages
951
Excel 2007.

This is probably something simple, haven't gotten it though... Making a button on my ribbon that will fire a macro. All the macro needs to do is say, "if sheetX is visible, then hide... if sheetX is hidden, then visible = true"

Here's where I'm at:
Code:
    For i = LBound(MyArray) To UBound(MyArray)
        If Sheets(MyArray(i)).Visible = True Then
            Sheets(MyArray(i)).visibe = xlHidden
        Else:
            If Sheets(MyArray(i)).Visible = xlHidden Then
                Sheets(MyArray(i)).Visible = True
            End If
        End If
    Next i

MyArray as dimmed variant and it's just a list of sheet names.
Getting error on "If Sheets(MyArray(i)).Visible = True Then"

Any help very much appreciated.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Excel 2007.

This is probably something simple, haven't gotten it though... Making a button on my ribbon that will fire a macro. All the macro needs to do is say, "if sheetX is visible, then hide... if sheetX is hidden, then visible = true"

Here's where I'm at:
Code:
    For i = LBound(MyArray) To UBound(MyArray)
        If Sheets(MyArray(i)).Visible = True Then
            Sheets(MyArray(i)).visibe = xlHidden
        Else:
            If Sheets(MyArray(i)).Visible = xlHidden Then
                Sheets(MyArray(i)).Visible = True
            End If
        End If
    Next i

MyArray as dimmed variant and it's just a list of sheet names.
Getting error on "If Sheets(MyArray(i)).Visible = True Then"
Since you are going for simple visible or not visible, this should work for you, this replacement code for what you posted should work for you...
Code:
For i = LBound(MyArray) To UBound(MyArray)
  Sheets(MyArray(i)).Visible = Not Sheets(MyArray(i)).Visible
Next i
 
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,702
Members
453,748
Latest member
akhtarf3

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