You have 2 potential issues here that I have run into doing a similar task.
1. When you auto name a tab you have to be sure it doesn't exceed the 30 (I
think) character limit or duplicate one that already exists.
2. Excel gets into a mess if you try to move or copy too many sheets between
workbooks using macros and generally bugs out.
My solution has been to switch between the workbooks and use the
"worksheets.add" function in your destination workbook. I have not yet found
a limit doing it his way.
In this code I am copying pages from "Rangefile" into my "Templatefile".'add sheet to template file and copy from current sheet in range plan
Workbooks(TemplateFile).Activate
Worksheets.Add
Range("a1").Select
ActiveSheet.Move after:=Worksheets(LastSheet)
Workbooks(RangeFile).Activate
Cells.Select
Selection.Copy
Workbooks(TemplateFile).Activate
Selection.PasteSpecial Paste:=xlPasteFormulas
Selection.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
'[add some code here to reformat the new tab]
Note that you have to add a sheet, go back and copy what you want to move
and then return to the destination to paste it; this may work with 'cut'
instead of 'copy' but I haven't tried it.
Later on I rename the new tab and update the "LastSheet" variable which
allows me to keep the sheets in order.
ActiveSheet.Name = [YourNewTabName]
LastSheet = ActiveSheet.Name
HTH
Giz
KenY said:
Using a macro, I can easily move a worksheet within a workbook using the line
worksheets("KY").move after:=worksheets(worksheets.count)
However, when I try to move the sheet to another workbook using the line
below (where tab_name is a text variable), I get a subscript out of range
error. Can anyone spot my silly mistake?
Workbooks("BV_Analysis_array_4.xls").Worksheets(tab_name).Move
before:=Workbooks("BVInf_10x_consolidator.xls").Worksheets(Worksheets.Count)
Thanks