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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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,221,526
Messages
6,160,340
Members
451,637
Latest member
hvp2262

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