+ Reply to Thread
Results 1 to 4 of 4

Selecting worksheets into groups?

  1. #1
    Ørjan Stien
    Guest

    Selecting worksheets into groups?

    How can I use VBA code to add worksheets to or subtract worksheets from
    groups?

    The problem occurs when users select several sheets for printing, when some
    of the sheets are not to be printed. I would like to remove one or more
    sheet from group before print dialog shows.

    I'm fine with a solution making me dissolve the entire group and then
    building the correct group, but cant get it to work.

    Have found code that let me create a group from scratch:
    This works:
    Sheets(Array("Week_01", "Week_02")).Select

    But this doesn't:
    MyString = """ & "Week_01" & """, """ & "Week_02" & """
    Sheets(Array(MyString)).Select

    Conclusion this far:
    Hardcoding the array works but making it flexible is hard.



  2. #2
    OJ
    Guest

    Re: Selecting worksheets into groups?

    Hi,
    try declaring a variable like this

    Dim intInc as Long, intCnt as Long, Sheets4Printing() as Long

    For intCnt = 1 to ThisWorkbook.Sheets.Count
    '''Code to determine whether the sheet is added or not
    redim Preserve Sheets4Printing(intInc)
    Sheets4Printing(intInc) = Sheets(intCnt).Index
    intInc = intInc + 1
    Next
    Sheets(Sheets4Printing).Select

    This adds the sheet indexes to an array which can then be used...
    Hth,
    OJ


  3. #3
    Tom Ogilvy
    Guest

    Re: Selecting worksheets into groups?

    Probably not significant, but just some added information, this assumes
    either no option base is specified and thus the default is 0 or that option
    base 0 is specified.

    Dim intInc as Long, intCnt as Long, Sheets4Printing() as Long

    Redim Sheets4Printing(0 to 0)
    intInc = 0
    For intCnt = 1 to ThisWorkbook.Sheets.Count
    '''Code to determine whether the sheet is added or not
    redim Preserve Sheets4Printing(0 to intInc)
    Sheets4Printing(intInc) = intCnt
    intInc = intInc + 1
    Next
    ' you can go directly to printout
    Sheets(Sheets4Printing).PrintOut

    would eliminate that concern. Also, Sheets(intCnt).Index is redundant as
    this should equal intCnt

    --
    Regards,
    Tom Ogilvy


    "OJ" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    > try declaring a variable like this
    >
    > Dim intInc as Long, intCnt as Long, Sheets4Printing() as Long
    >
    > For intCnt = 1 to ThisWorkbook.Sheets.Count
    > '''Code to determine whether the sheet is added or not
    > redim Preserve Sheets4Printing(intInc)
    > Sheets4Printing(intInc) = Sheets(intCnt).Index
    > intInc = intInc + 1
    > Next
    > Sheets(Sheets4Printing).Select
    >
    > This adds the sheet indexes to an array which can then be used...
    > Hth,
    > OJ
    >




  4. #4
    OJ
    Guest

    Re: Selecting worksheets into groups?

    Good point Tom....you're always adjusting my posts for the better!! ;o)


+ 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