Consulting

Results 1 to 8 of 8

Thread: Solved: Copy more than one sheet to new workbook

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Posts
    64
    Location

    Solved: Copy more than one sheet to new workbook

    Is there a way to copy more than one sheet (in their entirety) and then add a new workbook and paste them in there?

    Something like:
    [vba]
    Sub Sheet_Separator()
    Sheets(Array("Sheet1", "Sheet2")).Select
    Selection.Copy
    Workbooks.Add
    Selection.PasteSpecial
    End Sub

    [/vba]

    This only copies cell 'A1' on both sheets to sheets 1 and 2 in the new workbook...

    Thanks!

  2. #2
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    This works now
    [vba] Workbooks.Add
    Workbooks("book1").activate
    Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select

    Application.CutCopyMode = False
    Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Copy Before:=Workbooks("Book2"). _
    Sheets(1)[/vba]

  3. #3
    VBAX Regular
    Joined
    Jun 2008
    Posts
    64
    Location
    For some reason, I keep getting a 'subscript out of range' error when I try to activate my workbook in the following line:

    [VBA]
    Workbooks("Master File").activate
    [/VBA]

  4. #4
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    is "Master File" the name of your .xls?

  5. #5
    VBAX Regular
    Joined
    Jun 2008
    Posts
    64
    Location
    Yup.

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Maybe:
    [VBA]Option Explicit
    Sub CopySheets()
    Dim aShtLst As Variant
    aShtLst = Array("Sheet1", "Sheet2", "Sheet3")
    ThisWorkbook.Sheets(aShtLst).Copy
    Application.CutCopyMode = False
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    VBAX Regular
    Joined
    Jun 2008
    Posts
    64
    Location
    Beautiful, thank you!

  8. #8
    You know this could be done without VBA, Click on all the tabs to copy while holding down the ctrl key Then Right click one of the tabs, select 'move or copy'. In the 'to book' field select (new book), click the make copy check box, click OK. You then have a new workbook with all the tabs yoiu wanted.

Posting Permissions

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