Consulting

Results 1 to 5 of 5

Thread: Select multiple worksheets using list contained in worksheet

  1. #1
    VBAX Regular
    Joined
    Feb 2007
    Location
    Southampton, England
    Posts
    14
    Location

    Select multiple worksheets using list contained in worksheet

    Hi, I have a file which will be used as a template for a monthly report for several business units. I want to have a button which will print out a 'pack' of worksheets but it will not be all sheets in the book. The sheet names may vary across the business units, so I want to have a list of worksheet names in a consecutive range of cells and have the book select all of these sheets. My idea was to loop through the cells and collect the sheet names, but I cannot then get that into any acceptable format so I can say sheets.select(rangeofsheets).

    Can anyone help me with this please? The sheets to be selected are always going to be consecutive.

    Thanks
    Diana

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Greetings Diana,

    You did not mention which cells; or if these are filled-in with worksheet names based upon user input, some type of formula, another macros return, or ???.

    So, a close-eyes and swing blade: Might we want a userform, where the user could just select the first and last sheets; and print this range of sheets?

    Mark

  3. #3
    VBAX Regular
    Joined
    Feb 2007
    Location
    Southampton, England
    Posts
    14
    Location
    Hi, it's just a range of cells, let's say A15:A25 (although that varies depending on the lengh, the first cell is a named range so I can navigate to it easily) and the worksheet names are just typed in (by me to start with, then the user if they want to add/change) one to each cell.
    I don't think that would work as an approach as the sheets to be selected are not necessarity all next to each other.
    Thanks,
    Diana

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    IF… the cells which contain the sheet names are contiguous (no blanks in the list) and start at the named range Start and there are blank cells all around this list then this single line should do it for you:
    Sheets(Application.Transpose(Range("Start").CurrentRegion.Value)).PrintPreview
    If the above conditions don't pertain, then there will be other ways to ensure the list is right.. come back for that. (The code currently does print preview to save paper; you can replace .PrintPreview with .Printout.)
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Regular
    Joined
    Feb 2007
    Location
    Southampton, England
    Posts
    14
    Location
    That works for me. Thank you!
    Diana

Posting Permissions

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