Array Sheet

Partjob

Board Regular
Joined
Apr 17, 2008
Messages
139
Hi all
I can get the following sheet array by using the macro recorder.
Code:
Sheets(Array("EPN SUMMARY", "Dashboard", "Ian Cameron", "Vladimir", "Ken Golding", _
        "Andy Billings", "Stuart Weatherston", "Paul Symonds", "Peter Ball", "Ivan Key", _
        "PM2", "PM3", "PM4", "PM5")).Select
I need this line of code to be be more dynamic. The sheet names can change and can be added to.
I need a line to create a sheet array that includes all sheets except the sheet named "Dashboard" and sheet the named "EPN SUMMARY" or better still check if the sheet has the word "SUMMARY" in the name and exclude that from the array as I would use this in more than one workbook.

Thanks as always for your help
Partjob
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hello again
I am really struggling now!
I am trying to hide Columns based on date. The end result should be a 6 or 7 month window in a 18 month spread.
I can make this work on a loop through all sheets I was only trying to speed things up. I call the following on an open event
I don't realy understand what I am doing wrong.
I can record the hiding of columns across multiple sheets, but it does not work when the code is run.

Code:
Sub ProtectWB()
Dim wSheet As Worksheet
Application.ScreenUpdating = False
Application.EnableEvents = False
    For Each wSheet In Worksheets
        wSheet.Protect Password:="steve", _
            UserInterFaceOnly:=True, AllowFormattingRows:=True, AllowFormattingColumns:=True _
            , AllowFormattingCells:=True, AllowFiltering:=True
            Columns("F:Z").EntireColumn.Hidden = False
             Next wSheet
    
    'If wSheet.Name <> "Dashboard" Then
        Dim x As Range, z As Date, a As Integer
        z = DateAdd("m", -3, Date) 'date 3 months in past
             For Each x In Sheets("EPN SUMMARY").Range("F3:Z3")
            If x.Value > z Then 'check first column that is to be visible
                a = x.Column
                Sheets(Array("EPN SUMMARY", "Ian Cameron", "Vladimir", _
                "Ken Golding", "Andy Billings", "Stuart Weatherston", _
                "Paul Symonds", "Peter Ball", "Ivan Key", "PM2", _
                "PM3", "PM4", "PM5")).Select
            Sheet14.Activate
                If a = 6 Then
                Range(Columns(12), Columns(24)).EntireColumn.Hidden = True
                a = 100 'signal to exit
                Else
                    If a > 6 And a < 18 Then
                    Range(Columns(6), Columns(a - 1)).EntireColumn.Hidden = True
                    Range(Columns(a + 7), Columns(24)).EntireColumn.Hidden = True
                    a = 100 'signal to exit
                    Else
                    Range(Columns(6), Columns(17)).EntireColumn.Hidden = True
                    a = 100 'signal to exit
                    End If
                End If
            
            End If
            If a = 100 Then
            Sheet1.Select
            Application.ScreenUpdating = True
            Application.EnableEvents = True
            Exit Sub
            End If
        Next x
    'End If
   
    Application.ScreenUpdating = True
    Application.EnableEvents = True
End Sub

I need guidance on this, thank you.
Partjob
 
Upvote 0
I have gone back to looping through on this, a bit juggling the loops around has speeded things up.
Unless anyone can suggest a way of making this more efficient, then I will live with this.

Code:
Sub ProtectWB()
Dim wSheet As Worksheet, x As Range, z As Date, a As Integer
z = DateAdd("m", -3, Date) 'date 3 months in past
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each x In Sheets("EPN SUMMARY").Range("F3:Z3")
            If x.Value > z Then 'check first column that is to be visible
                a = x.Column
              
    For Each wSheet In Worksheets
        wSheet.Protect Password:="steve", _
            UserInterFaceOnly:=True, AllowFormattingRows:=True, AllowFormattingColumns:=True _
            , AllowFormattingCells:=True, AllowFiltering:=True
 
    If wSheet.Name <> "Dashboard" Then
        
                wSheet.Select
                Columns("F:Z").EntireColumn.Hidden = False
                If a = 6 Then
                
                Range(Columns(12), Columns(24)).EntireColumn.Hidden = True
               
                Else
                    If a > 6 And a < 18 Then
                    Range(Columns(6), Columns(a - 1)).EntireColumn.Hidden = True
                    Range(Columns(a + 7), Columns(24)).EntireColumn.Hidden = True
                    
                    Else
                    Range(Columns(6), Columns(17)).EntireColumn.Hidden = True
                    
                    End If
                End If
            
            End If
     
    Next wSheet
    End If
    If a > 0 Then
            Sheet1.Select
            Application.ScreenUpdating = True
            Application.EnableEvents = True
            Exit Sub
            End If
     Next x
End Sub

Thanks for the imput.
Partjob
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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