+ Reply to Thread
Results 1 to 8 of 8

Copy multiple sheets in a new workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    04-16-2015
    Location
    Madrid
    MS-Off Ver
    2010
    Posts
    7

    Copy multiple sheets in a new workbook

    Hi,
    I have a file which has 5 sheets and I am creating a macro which should copy 3 sheets (GP_Approval, Country; Summary) into a new workbook.
    It seems like my code is not the appropriate one. Thank you.

    Sub Copysheets()
    Dim wbI As Workbook
    Dim wbO As Workbook
    Dim wsI As Worksheet
    Dim i As Integer
    
    
    Set wbI = ThisWorkbook
    Set wbO = Workbook.Add
    
    For i = 1 To wbI.Sheets.Count
    If wsI(i).Name = "GP_Approval" Then wsI(i).Copy
    If wsI(i).Name = "Country" Then wsI(i).Copy
    If wsI(i).Name = "Summary" Then wsI(i).Copy
    
    Next
    
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Copy multiple sheets in a new workbook

    maybe try this?

    Sub Copysheets()
    Dim wbI As Workbook
    Dim wbO As Workbook
    Dim wsI As Worksheet
    Dim i As Integer
    
    
    Set wbI = ThisWorkbook
    Set wbO = Workbook.Add
    
    For i = 1 To wbI.Sheets.Count
    If wsI(i).Name = "GP_Approval" Then wsI(i).Copy after:=wbO(wbO.Sheets.Count)
    If wsI(i).Name = "Country" Then wsI(i).Copy after:=wbO(wbO.Sheets.Count)
    If wsI(i).Name = "Summary" Then wsI(i).Copy after:=wbO(wbO.Sheets.Count)
    end if
    end if
    end if
    Next
    
    End Sub
    (untested)
    Hope I could help - if your post has been solved don't forget to mark it as such.

    Clicking the * below is a great way to say thanks!

    "Drowning in 10 feet of water isn?t any different than drowning in a million feet. And if you can swim, it doesn?t matter how deep the ocean is. At some level, once you realize you?re in water that?s too deep to stand, you have to have a very different approach," - Joi Ito

  3. #3
    Registered User
    Join Date
    04-16-2015
    Location
    Madrid
    MS-Off Ver
    2010
    Posts
    7

    Re: Copy multiple sheets in a new workbook

    Thanks but unfortunately, it gives me also error.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,683

    Re: Copy multiple sheets in a new workbook

    you have omitted the paste portion of the copy/paste routine

    Here are a couple of scenarios to learn this:

    http://stackoverflow.com/questions/6...book-using-vba
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    04-16-2015
    Location
    Madrid
    MS-Off Ver
    2010
    Posts
    7

    Re: Copy multiple sheets in a new workbook

    Simarui, Thanks but unfortunately, it gives me also error.

  6. #6
    Forum Contributor LokeshKumar's Avatar
    Join Date
    03-31-2015
    Location
    India
    MS-Off Ver
    All, mostly 2010 now..
    Posts
    471

    Re: Copy multiple sheets in a new workbook

    Could you please upload the workbook....?
    Last edited by LokeshKumar; 04-17-2015 at 09:01 AM.
    Lokesh Kumar
    Stay Hungry.. Stay Foolish..
    _________________________________________________________
    Please Click STAR to Add Reputation if my/someone's answer helped!

  7. #7
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Copy multiple sheets in a new workbook

    this seems to be working:

    Sub Copysheets()
    Dim wbI As Workbook
    Dim wbO As Workbook
    Dim wsI As Worksheet
    Dim i As Integer
    
    
    Set wbI = ThisWorkbook
    Set wbO = Workbooks.Add
    
    For i = 1 To wbI.Sheets.Count
    Set wsI = wbI.Sheets(i)
    If wsI.Name = "GP_Approval" Then wsI.Copy after:=wbO.Sheets(wbO.Sheets.Count)
    If wsI.Name = "Country" Then wsI.Copy after:=wbO.Sheets(wbO.Sheets.Count)
    If wsI.Name = "Summary" Then wsI.Copy after:=wbO.Sheets(wbO.Sheets.Count)
    
    Next
    
    End Sub

  8. #8
    Registered User
    Join Date
    04-16-2015
    Location
    Madrid
    MS-Off Ver
    2010
    Posts
    7

    Re: Copy multiple sheets in a new workbook

    Thank you Simarui.
    That works perfectly

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2015, 05:12 AM
  2. Replies: 1
    Last Post: 09-23-2014, 06:42 PM
  3. [SOLVED] Macro to copy cells from multiple sheets in workbook to multiple sheets in other workbook
    By KeithMale in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2013, 05:37 PM
  4. Replies: 3
    Last Post: 09-07-2012, 02:50 PM
  5. Copy rows from multiple sheets in one workbook into a different workbook
    By maneeshagr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-12-2012, 06:24 AM

Tags for this Thread

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