ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy from one work to another (https://www.excelbanter.com/excel-programming/402392-copy-one-work-another.html)

jln via OfficeKB.com

Copy from one work to another
 
What im trying to do is this. I have a main work book that opens another work
book then copys a tab into the main work book. Now I have to add more then
the one tab to the 2nd work book and copy all tab to the main. Now in the 2nd
workbook it can have 1 to 5 tabs and i need to make sure i get all the tabs.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200712/1


joel

Copy from one work to another
 
The code below copies only the sheets that are in the 2nd workbook and not in
the main workbook

Sub copysheets()

Workbooks.Open Filename:="second.xls"
For Each second_ws In Workbooks("second.xls").Sheets
Found = False
For Each main_ws In ThisWorkbook.Sheets
If second_ws.Name = main_ws.Name Then
Found = True
Exit For
End If
Next main_ws
If Found = False Then
With ThisWorkbook
second_ws.Copy after:=.Sheets(.Sheets.Count)
End With
End If

Next second_ws
End Sub

"jln via OfficeKB.com" wrote:

What im trying to do is this. I have a main work book that opens another work
book then copys a tab into the main work book. Now I have to add more then
the one tab to the 2nd work book and copy all tab to the main. Now in the 2nd
workbook it can have 1 to 5 tabs and i need to make sure i get all the tabs.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200712/1




All times are GMT +1. The time now is 03:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com