Copy Worksheets into already existing Workbooks with VBA

mrsleepy95

New Member
Joined
Feb 5, 2018
Messages
4
I have a Workbook that has 10 different Worksheets in it, all with their individual names. Then I have 10 separate Workbooks, all with names corresponding to the Worksheets names. I am looking to copy each worksheet in the original Workbook into its relative individual workbook.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
What is the full path to the folder containing the separate workbooks? Are the ten files the only files in that folder? Can you list 3 or 4 worksheet names with their corresponding workbook names including their extension (xls, xlsx, xlsm)?
 
Upvote 0
What is the full path to the folder containing the separate workbooks? Are the ten files the only files in that folder? Can you list 3 or 4 worksheet names with their corresponding workbook names including their extension (xls, xlsx, xlsm)?

The full path to the folder containing the separate workbooks is F:\Master Workbooks\Calgary Change Variables 1971-2006\Prop

I used 10 files as an example, but there are actually files in that folder. A few examples of the worksheet names are "HH Gross Rent 30 Perc Inc LQ", "HH Owners Pay 30 Perc Inc LQ", and Avg HH Inc LQ". Their corresponding workbook names are exactly the same. The extensions are .xlsb.
 
Upvote 0
The full path to the folder containing the separate workbooks is F:\Master Workbooks\Calgary Change Variables 1971-2006\Prop

I used 10 files as an example, but there are actually files in that folder. A few examples of the worksheet names are "HH Gross Rent 30 Perc Inc LQ", "HH Owners Pay 30 Perc Inc LQ", and Avg HH Inc LQ". Their corresponding workbook names are exactly the same. The extensions are .xlsb.

Sorry, I meant that there are 69 files in that folder.
 
Upvote 0
Try:
Code:
Sub CopySheet()
    Application.ScreenUpdating = False
    Dim wkbDest As Workbook
    Dim wkbSource As Workbook
    Set wkbSource = ThisWorkbook
    Dim ws As Worksheet
    For Each ws In wkbSource.Sheets
        Set wkbDest = Workbooks.Open("F:\Master Workbooks\Calgary Change Variables 1971-2006\Prop\" & ws.Name & ".xlsb")
        ws.Copy after:=Sheets(Sheets.Count)
        wkbDest.Close True
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
Code:
Sub CopySheet()
    Application.ScreenUpdating = False
    Dim wkbDest As Workbook
    Dim wkbSource As Workbook
    Set wkbSource = ThisWorkbook
    Dim ws As Worksheet
    For Each ws In wkbSource.Sheets
        Set wkbDest = Workbooks.Open("F:\Master Workbooks\Calgary Change Variables 1971-2006\Prop\" & ws.Name & ".xlsb")
        ws.Copy after:=Sheets(Sheets.Count)
        wkbDest.Close True
    Next ws
    Application.ScreenUpdating = True
End Sub

This worked perfectly, thank you so much!
 
Upvote 0
Cross posted https://www.excelforum.com/excel-pr...into-already-existing-workbooks-with-vba.html

Cross-Posting
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,858
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top