Dear All,
I am using the coding below to loop through all the sheets except 1(Team Summary) in a workbook, and copy the data from each sheet to a new 1 sheet workbook and then save that workbook in a location depending on the sheet name, It works fine for the first 6 sheets and always crashed on the 7th sheet, is there away to make this easier, the data I have is 11 teams of refund data,in the workings sheet is a list of all team names with the pathname next to it. Does anyone know why it keeps crashing and does anyone know how to make this easier.
Sub copyagentsheets()
Dim newsheets As Long, OldSheets As Long
Windows("New weekly refund template.xls"
.Activate
ActiveWindow.ActivateNext
For Each wwsht In Sheets(Array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
wwsht.Select
sname = [d7].Value
If [d1].Value = 0 Then GoTo ehand
OldSheets = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = "1"
Workbooks.Add
Application.SheetsInNewWorkbook = OldSheets
ActiveWindow.ActivateNext
Cells.Copy
ActiveWindow.ActivatePrevious
ActiveSheet.Paste
ActiveSheet.Name = sname
ActiveWindow.ActivateNext
Windows("New Weekly Refund Template.xls"
.Activate
Sheets("workings"
.Select
Columns("a:a"
.Select
Selection.Find(What:=sname, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
savename = ActiveCell.Offset(0, 2).Value
ActiveWindow.ActivatePrevious
ActiveWorkbook.SaveAs Filename:=savename, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
savename = 0
ActiveWorkbook.Close
ActiveWindow.ActivateNext
ehand:
Next wwsht
End Sub
Thanks
Thanks Rob.![[yoda] [yoda] [yoda]](/data/assets/smilies/yoda.gif)
I am using the coding below to loop through all the sheets except 1(Team Summary) in a workbook, and copy the data from each sheet to a new 1 sheet workbook and then save that workbook in a location depending on the sheet name, It works fine for the first 6 sheets and always crashed on the 7th sheet, is there away to make this easier, the data I have is 11 teams of refund data,in the workings sheet is a list of all team names with the pathname next to it. Does anyone know why it keeps crashing and does anyone know how to make this easier.
Sub copyagentsheets()
Dim newsheets As Long, OldSheets As Long
Windows("New weekly refund template.xls"
ActiveWindow.ActivateNext
For Each wwsht In Sheets(Array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
wwsht.Select
sname = [d7].Value
If [d1].Value = 0 Then GoTo ehand
OldSheets = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = "1"
Workbooks.Add
Application.SheetsInNewWorkbook = OldSheets
ActiveWindow.ActivateNext
Cells.Copy
ActiveWindow.ActivatePrevious
ActiveSheet.Paste
ActiveSheet.Name = sname
ActiveWindow.ActivateNext
Windows("New Weekly Refund Template.xls"
Sheets("workings"
Columns("a:a"
Selection.Find(What:=sname, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
savename = ActiveCell.Offset(0, 2).Value
ActiveWindow.ActivatePrevious
ActiveWorkbook.SaveAs Filename:=savename, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
savename = 0
ActiveWorkbook.Close
ActiveWindow.ActivateNext
ehand:
Next wwsht
End Sub
Thanks
Thanks Rob.
![[yoda] [yoda] [yoda]](/data/assets/smilies/yoda.gif)