+ Reply to Thread
Results 1 to 7 of 7

ADD sheets to array

  1. #1
    Registered User
    Join Date
    11-11-2008
    Location
    Wilmington
    Posts
    26

    Talking ADD sheets to array

    What VBA code would I use to add all sheets in a workbook to an array EXCEPT "Sheet1" ??

    The sheet names will change but "sheet1" will always stay the same.

    After getting them added to the array , I want to sum Column E in Cell F1...

    This shold be very simple macro to do this but I am not sure how to get started by selecting all the sheets EXCEPT sheet1



    Sheet 1 has all my data, and a macro creates approx 50 other sheets all named differently with respect to the data in sheet1. I then just need to Sum column E for all 50 sheets.

  2. #2
    Registered User
    Join Date
    11-11-2008
    Location
    Wilmington
    Posts
    26

    Re: ADD sheets to array

    I now see I could use

    ActiveWorkbook.sheets.Select

    but that gets all the sheets. When in turn i need ALL The sheets, except sheet1

  3. #3
    Registered User
    Join Date
    03-28-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: ADD sheets to array

    Hey eighty2scrambler,

    Try this:

    Please Login or Register  to view this content.
    Warm regards,

    Shampoo Monkey

    If you are happy with the results, please add to my reputation by clicking the icon next to the Post # in the bar above this post.

  4. #4
    Registered User
    Join Date
    11-11-2008
    Location
    Wilmington
    Posts
    26

    Re: ADD sheets to array

    Thanks !!!!
    I used the below. But your idea is exactly what I needed.!


    Sub SelectAllButFirst()
    Dim wSht As Worksheet

    For Each wSht In Worksheets
    If wSht.Name <> "Sheet1" Then
    wSht.Select (False)
    End If
    Next wSht
    End Sub

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: ADD sheets to array

    Please encase any/all VBA within CODE tags per Forum rules (and as illustrated in Shampoo Monkey's post)

    Re: name testing, ie:

    Please Login or Register  to view this content.
    it's worth being aware of the fact that by default VBA (unlike Native XL) is case sensitive so SHEET1 <> Sheet1

    In this instance this is not likely to be an issue but generally speaking when comparing strings in VBA it's best to normalise them either by:

    a) comparing in common case:

    Please Login or Register  to view this content.
    or

    b) use StrComp function

    Please Login or Register  to view this content.
    You can also set the entire Module to be case insensitive by adding

    Please Login or Register  to view this content.
    to the head of the module, however, most would opt to control case sensitivity on an "as and when" required basis rather than applying to a module in it's entirety.
    Last edited by DonkeyOte; 04-29-2010 at 04:45 AM. Reason: re-worded

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,317

    Re: ADD sheets to array

    You should also be aware that if Sheet1 is the active sheet, then this:
    Please Login or Register  to view this content.
    will select ALL sheets.
    Everyone who confuses correlation and causation ends up dead.

  7. #7
    Registered User
    Join Date
    11-11-2008
    Location
    Wilmington
    Posts
    26

    Re: ADD sheets to array

    just when you thought you knew it all.....

    Thanks guys!

+ 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