Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hi all! I must say that this forum has been helpful in leaps and bounds! Anyways, I have code that cycles through all sheets in workbook1, and then copies a specific range to the corresponding worksheets (with like names) in workbook2. [PHASE 1] Now my problem is that I need code that will cycle through all worksheets in workbook1, and compare the names of them to those in workbook2. If a worksheet (i.e. worksheet name) exists in the first workbook, but not in the second workbook, then this specific sheet (including all formulas, formats etc.) in its entirety must be copied to the second workbook...[PHASE 2] Bear in mind that an indefinite number of worksheets will be added over time (into workbook1), of which the sheet names will be unknown (i.e. I may not use specific sheet names in the macro (i.e worksheets ("ListA").Copy, etc. can not be used. ALSO, The amount of sheets workbook1 is unknown. Makes sense? If it does, please help!!! SOS :) Here's the code I've got for the first phase: Sub Copy_Stuff () Dim TargetWB As Workbook Dim SourceWB As Workbook Dim TargetWS As Worksheet Dim SourceWS As Worksheet Dim SourceRange As Range Set TargetWB = Workbooks.Open(ThisWorkbook.Path & "\Price Lists1.xlsm", ignorereadonlyrecommended:=True) Set SourceWB = Workbooks.Open(ThisWorkbook.Path & "\Price Lists2.xlsm", ignorereadonlyrecommended:=True) Workbooks("Price Lists2.xlsm").Activate For Each SourceWS In Worksheets Set SourceRange = SourceWS.Range("C13:X100") Workbooks("Price Lists1.xlsm").Activate For Each TargetWS In Worksheets If TargetWS.Name = SourceWS.Name Then SourceRange.Copy TargetWS.Range("C13").PasteSpecial xlPasteAll 'PLACE NEW CODE HERE...??? after ELSE statement...??? Exit For End If Next TargetWS Next SourceWS Set TargetWB = Nothing Set SourceWB = Nothing Set SourceRange = Nothing End Sub Any Idea of code I can use for phase 2 in the ['PLACE NEW CODE HERE...??? after ELSE statement...???] area? Any other suggestions are also welcome. Thanx in advance... ARbitOUR -- ARbitOUR ------------------------------------------------------------------------ ARbitOUR's Profile: http://www.thecodecage.com/forumz/member.php?userid=254 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=100430 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I duplicate value in multiple worksheets in same workbook? | Excel Discussion (Misc queries) | |||
copy sheets in workbook to new workbook | Excel Programming | |||
Copy four worksheets from one workbook into a new workbook.e-mail | Excel Programming | |||
how do i look through worksheets in a workbook to find duplicate | Excel Worksheet Functions | |||
copy a workbook from other workbook with lot of sheets wit... | Excel Discussion (Misc queries) |