Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Apr 2016
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Copying a desired sheet

    Hello everyone,

    I have a small problem and I hope you can help me fix it.

    I need to copy one sheet from a workbook which has almost 10 other sheets to another workbook (excel file), the code I have until now copies all the sheets (because its a for loop) and I have been trying to adjust it so it would copy just the sheet that I want. any ideas people? (the name of the sheet that I only need copied is 2 - Execution.

    this is a sample of code I have been using:
    Code:
    Sub CopySheets()
    Dim OverviewProjectsWorkbook As Workbook
    Dim CurrentProjectsWorkbook  As Workbook
    Set OverviewProjectsWorkbook = Workbooks("Overview Projects")
    Set CurrentProjectsWorkbook = Workbooks("Current Projects")
    Dim OverviewProjectsSheet As Worksheet
    For Each OverviewProjectsSheet In OverviewProjectsWorkbook.Sheets
    OverviewProjectsSheet.Copy After:=CurrentProjectsWorkbook.Sheets(CurrentProjectsWorkbook.Sheets.Count)
    Next
    End Sub
    so what should I add/change to the code so it would copy just one desired sheet?


    Thank you in advance people!!
    Last edited by RetiredGeek; 2016-04-12 at 15:58. Reason: Added Code Tags

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Luai,

    This should do the trick:
    Code:
    Sub CopySheets()
    Dim OverviewProjectsWorkbook As Workbook
    Dim CurrentProjectsWorkbook  As Workbook
    Set OverviewProjectsWorkbook = Workbooks("Overview Projects")
    Set CurrentProjectsWorkbook = Workbooks("Current Projects")
    Dim OverviewProjectsSheet As Worksheet
    For Each OverviewProjectsSheet In OverviewProjectsWorkbook.Sheets
        If OverviewProjectsSheet.Name = "2 - Execution" Then
          OverviewProjectsSheet.Copy After:=CurrentProjectsWorkbook.Sheets(CurrentProjectsWorkbook.Sheets.Count)
        End If
    Next
    End Sub
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    New Lounger
    Join Date
    Apr 2016
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you RG! it worked I truly appreciate your help!!
    Last edited by luai94; 2016-04-13 at 09:47.

Posting Permissions

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