It's probably this line of code
Change the AND to ORVB:If ws. Name = ("OP KPI 1 pivot") And ws.Name = ("OP KPI 2 pivot") Then
HTHVB:If ws. Name = ("OP KPI 1 pivot") Or ws.Name = ("OP KPI 2 pivot") Then
Craig
I'm trying to unhide several sheets (then hide them again at the end of the macro using = False). When I run this macro nothing happens. What's wrong with the code?
VB:For Each ws In Worksheets If ws.Name = ("OP KPI 1 pivot") And ws.Name = ("OP KPI 2 pivot") Then With ws .Visible = True End With End If Next ws
It's probably this line of code
Change the AND to ORVB:If ws. Name = ("OP KPI 1 pivot") And ws.Name = ("OP KPI 2 pivot") Then
HTHVB:If ws. Name = ("OP KPI 1 pivot") Or ws.Name = ("OP KPI 2 pivot") Then
Craig
VB:Sub Show_Hide_Sheets() Dim ws As Worksheet For Each ws In Worksheets If ws.Name = "Sheet1" Or ws.Name = "Sheet2" Then ws.Visible = Not ws.Visible End If Next ws End Sub
AAE
----------------------------------------------------
Forum Rules | Message to Cross Posters | How to use Tags
Thanks for getting back to me so quickly. But if I try with all the sheets, I get a syntax error, and I can't figure out what's wrong:
VB:For Each ws In Worksheets If ws.Name = ("OP KPI 1 pivot") Or ws.Name = ("OP KPI 2 pivot") Or ws.Name = ("OP KPI 3 pivot") Or ws.Name = ("OP KPI 4 pivot"), _ Or ws.Name = ("OP KPI 5 pivot") Or ws.Name = ("SC KPI 1 pivot") Or ws.Name = ("SC KPI 2 pivot") Or ws.Name = ("SC KPI 3 pivot"), _ Or ws.Name = ("SC KPI 4 pivot") Then With ws .Visible = True End With End If Next ws
A Select Case Statement would the best.
Why not just show ALL sheets and hide the ones to remain remain hidden, if any?
Or, use something like;
Your code fails due the commas before the line continuation characters.VB:ws.Visible=ws.Name Like "*pivot"
You got a point, Dave. I'll try that. Thanks.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks