Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Deselect first two sheets

  1. #1
    Guest

    Default

    I want to deselect sheets 1 (Master) and 2 (Prep) where I have another 40 sheets also selected in a macro. So as to leave only the 40 sheets selected.

  2. #2
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-03-08 20:14, Anonymous wrote:
    I want to deselect sheets 1 (Master) and 2 (Prep) where I have another 40 sheets also selected in a macro. So as to leave only the 40 sheets selected.
    If you have 40 sheets + these 2 then this
    may help....

    Sub SelectAllSheets()
    Dim sh As Worksheet
    Dim i As Single

    'make sure we Start off with another sheet other then these 2
    Do Until ActiveSheet.Name <> "Master" And ActiveSheet.Name <> "Prep"
    Sheets(i + 1).Select
    i = i + 1
    Loop
    'Now select all bar 2
    For Each sh In ActiveWorkbook.Sheets
    If sh.Name <> "Master" And sh.Name <> "Prep" Then
    sh.Select False
    End If
    Next

    End Sub


    Ivan

  3. #3
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi

    Just to give you a couple more ideas to expand on Ivans answer, try:

    Dim sh As Worksheet

    On Error Resume Next
    For Each sh In ActiveWorkbook.Sheets
    sh.Visible = Not (sh.Name = "Master" Or sh.Name = "Prep")
    sh.Select False
    Next

    End Sub

  4. #4
    Guest

    Default

    Thanks for that guys. Unfortunately the first two are always selected at the start.

    Dave. I see you hide the two sheets, this looks like the better route

    Tks

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •