Consulting

Results 1 to 8 of 8

Thread: How to produce two workbooks from a larger workbook

  1. #1

    How to produce two workbooks from a larger workbook

    Folks I hope this is simple. I have a workbook that has many sheets that I used to use to produce sa single report, using the first line "Sheets(Array......" instruction below.

    I now want it to produce a second workbook containing different sheets from the original workbook. So I added the second line "Sheets(Array....) instruction but it doesn't like it. Is there a simple way round this for you clever folks.


    "[VBA]"
    Sheets(Array("Report","COpen", "CClosed", "CNew","WAll", "WOpen", "WClosed","WNew")).Copy
    Sheets(Array("CImport", "WImport")).Copy
    [/VBA]"

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,874
    Works here; what's the error message?
    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.

  3. #3
    Thanks for your reply p45cal. Think it was subscript out of range. But it was on my work PC so I'll check tomorrow and post an update. Your prompt has got me thinking, it's been a long day at work. When the first Sheets(Array...) instruction is run it creates the new workbook, I need to then activate the original workbook before running the second Sheets(Array...) instruction.

    I'll check in the morning to see if that works it should do.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,874
    Quote Originally Posted by LutonBarry View Post
    Think it was subscript out of range.
    Then you've got one or more sheet names not an exact replica of the actual sheet name - check for spaces and the like.



    Quote Originally Posted by LutonBarry View Post
    When the first Sheets(Array...) instruction is run it creates the new workbook, I need to then activate the original workbook before running the second Sheets(Array...) instruction
    Didn't need to here, it depends in which workbook the code is in and perhaps where the code is in that workbook.
    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
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Thisworkbook.Sheets(Array("Report","COpen", "CClosed", "CNew","WAll", "WOpen", "WClosed","WNew")).Copy 
    Thisworkbook.Sheets(Array("CImport", "WImport")).Copy

  6. #6
    p45call. Yes that was it when you create the copy of the sheets the new workbook is the activated one. I just needed to reactivate the original wherethe code was held and it worked.

    Thanks for your help.

  7. #7

  8. #8
    snb, Ooops I did and thanks very much, less code and yet another learning from this great forum.

    Thanks again.

Posting Permissions

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