+ Reply to Thread
Results 1 to 15 of 15

Select Multiple Sheets based on List

Hybrid View

  1. #1
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    oh right sorry i have loaded them into a array so you can access them sheets, sorry i didnt realise that you wanted them selected. i will have a look to see if i can work that one out
    There are only 10 types of people in the world:
    Those who understand binary, and those who don't!

  2. #2
    Registered User
    Join Date
    07-30-2007
    Posts
    61
    ok
    cheers

  3. #3
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    sorry roasty_1, i cant seem to get it to work no matter what i try.

    does anybody else know how to do this as i am now interested.

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try attached file.

    Regards,
    Antonio
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    07-30-2007
    Posts
    61
    Thanks Antonio

    Works well, only it crashes Excel if any of the cells are left blank, not an issue though, can work round that.

    thanks for your help.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481
    There are a couple of ways of selecting the sheets.
    Either using the Replace argument or by building an array of sheetnames.

    Private Sub SelectSheets_Click()
    
        Dim blnReplace As Boolean
        Dim lngRow As Long
        
        blnReplace = True
        For lngRow = 3 To 21
            If Cells(lngRow, 2) = "Y" Then
                Sheets(Cells(lngRow, 1).Value).Select blnReplace
                blnReplace = False
            End If
        Next
        MsgBox "Using Replace"
        
        Me.Select   ' clear selection
        
        Dim lngNSheets As Long
        Dim lngCount As Long
        
        lngNSheets = Application.WorksheetFunction.CountIf(Range("B3:B21"), "Y")
        ReDim vntSheets(1 To lngNSheets) As Variant
        
        For lngRow = 3 To 21
            If Cells(lngRow, 2) = "Y" Then
                lngCount = lngCount + 1
                vntSheets(lngCount) = Cells(lngRow, 1)
            End If
        Next
        Sheets(vntSheets).Select
        MsgBox "Using array"
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  7. #7
    Registered User
    Join Date
    07-30-2007
    Posts
    61
    Hi Andy

    thanks for your help, couldnt get your code to work unfortunetly, thanks anyway.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481
    In what way did it not work?

    raised an error
    No selection of sheets

  9. #9
    Registered User
    Join Date
    07-30-2007
    Posts
    61
    weird, it works now, before I was getting an Object error

    Now works fine

    Thanks!!

+ 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