select all but certain sheets

chris9104

Board Regular
Joined
Feb 7, 2009
Messages
55
Evening all, is there any way to select all but certain sheets at the same time when the number of sheets and the names will always vary. I can select all of them without a problem, I just cant manage to exclude any.

Alternatively is it possible to select a range of sheets when I don't know how many there will be? eg select sheets first:last like you could do with a formula
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi Chris,

Yes, you can select all the worksheets using the worksheets object collection select method:
Code:
Worksheets.Select

To select the worksheets with indexes 1,3,4 you could use:
Code:
Worksheets(Array(1, 3, 4)).Select

Incidentally, why do you want to select them - what do you plan to do with them?

Hope that helps
 
Upvote 0
Hi Colin, i'll be looking to print the sheets.

I don't know whether the array will work because I dont know how many sheets there will be. The worksheets are called the same as the range "Names" on one of the sheets if thats any use.
 
Upvote 0
Hi Chris,

In that case you don't need to select the sheets.


So, let's recap.

There will be a varying number of sheets and their names may change. You want to print some of them?

How do you know which sheets you want to print?
Is it that you want to print all sheets except for certain ones? If that's the case, then which sheets do you want to exclude?
 
Upvote 0
Thanks Colin, thats correct.

I am wanting to print all sheets except for "Staff Data","First","Last" and "Reference Data"
 
Upvote 0
Hi Chris

And will the names of those worksheets change?
 
Upvote 0
Hi Chris,

Something like this should work:
Code:
Sub Example()
    Dim strarrToPrint() As String
    Dim lCounter As Long
    Dim lWst As Long
 
    With Worksheets
        For lWst = 1 To .Count
 
            With .Item(lWst)
 
                Select Case .Name
                    Case "Staff Data", "First", "Last", "Reference Data"
                    Case Else
                        If .Visible = xlSheetVisible Then
                            lCounter = lCounter + 1
                            ReDim Preserve strarrToPrint(1 To lCounter)
                            strarrToPrint(lCounter) = .Name
                        End If
                End Select
            End With
        Next lWst
 
        If LenB(Join(strarrToPrint, "")) > 0 Then .Item(strarrToPrint).PrintOut
    End With
 
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,206,761
Messages
6,074,786
Members
446,088
Latest member
Koustubh12

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