+ Reply to Thread
Results 1 to 3 of 3

Selecting an array with a varying number of sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    06-13-2008
    Posts
    8

    Selecting an array with a varying number of sheets

    Hi,

    I am making a macro and I am having trouble getting it to select all of my tabs at the same time so I can simultaneously make changes to all of them. The problem is that I need to be able to add new tabs without editing the macro. I have a tab for each state, and if I add a new state, the macro will not select the new tab and I have to add the new tab name into the array of sheets that are being selected. Is there a way to select all sheets from say the 3rd tab until the one before a tab named "Reference"?

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441
    Try,

    Sub SelectMySheets()
    
        Dim lngIndex As Long
        Dim blnReplace As Boolean
        
        blnReplace = True
        With ActiveWorkbook
            For lngIndex = 3 To .Sheets.Count
                If UCase(.Sheets(lngIndex).Name) = "REFERENCE" Then Exit For
                .Sheets(lngIndex).Select blnReplace
                blnReplace = False
            Next
        End With
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    06-13-2008
    Posts
    8
    First of all, thank you so much for your help, that was a huge problem for me I honestly appreciate it more than you probably think. Second, wow, that was really fast!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1