• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Select All But 2 Sheets

Brandi

New Member
I have written a Macro that will select all but the last 2 sheets. I need it to be the Active Sheets, which it is doing, but if I have sheets hidden, it gives me the dreaded 400 Error. If sheets are not hidden, it runs perfectly. I am at a loss, what am I missing?

Code:

As with Your previous thread >>> use code - tags <<<
Code:
Sub SelectAllSheets()
    Dim x As Integer
    ThisWorkbook.Worksheets(2).Select
    For x = 1 To ((ThisWorkbook.Worksheets.Count) - 2)
        Worksheets(x).Select (False)
    Next x
End Sub
 

Attachments

  • SampleCR.xlsm
    96 KB · Views: 1
Last edited by a moderator:
Not sure I understand the question? I do not want to select the hidden sheets, only visible sheets. The original workbook has multiple hidden sheets and I finally figured out that the error is occurring when I have hidden sheets in the workbook, but Not if all sheets are visible. So, my question is, how do I modify the code to recognize that I Only want the visible sheets, so that it will not throw an error?
 
Brandi
You cannot select hidden sheet - am I right?
As well as Excel cannot do it.
As well as You, then You're selecting sheets then You'll always 'check' can You see it ( is it visible ).
With Excel, You could do it too.
I modified that Your code in this file.
 

Attachments

  • SampleCR (1).xlsm
    96 KB · Views: 2
Back
Top