I have a worksheet, which I split into separate workbooks. this I have a mcro for and it works well. I would like to add some code that after splitting, i can copy three worksheets from another different workbook ( these are not new sheets, they are different report), and copy them over to each of the workbooks created by the first macro.
I have tried nesting the second needed macro into the first, putting it into various locations, but can't seem to get it to work.
The inital macro (Public Sub Split_It) is from this board.
I have tried to label what i am trying to add:
Public Sub Split_It2()
Dim iWorksheet As Integer 'loop variable
Dim sFilename As String, sPath As String
sPath = GetFolder()
If Len(sPath) = 0 Then Exit Sub
sPath = sPath & "\"
On Error Resume Next
'loop through all worksheets
For iWorksheet = 1 To ActiveWorkbook.Worksheets.Count
Worksheets(iWorksheet).Activate
'set the filename for the output file
sFilename = sPath & ActiveSheet.Name & ".xlsx"
'copy the active sheet into new workbook
ActiveSheet.Copy
ActiveWorkbook.SaveAs _
Filename:=sFilename, _
FileFormat:=51, _
Password:="", _
CreateBackup:=False
Windows("ABC.xlsx").Activate
Sheets(Array("Jan", "Feb", "Mar")).Select -- this line is mine
Sheets(Array("Jan", "Feb", "Mar")).Copy Before:=Workbooks( _ -- this line is mine
"*.xlsx").Sheets(3)[/B] ActiveWorkbook.Close -- this line is mine
Next iWorksheet
End Sub
thanks in advance.
Regards.
struf
I have tried nesting the second needed macro into the first, putting it into various locations, but can't seem to get it to work.
The inital macro (Public Sub Split_It) is from this board.
I have tried to label what i am trying to add:
Public Sub Split_It2()
Dim iWorksheet As Integer 'loop variable
Dim sFilename As String, sPath As String
sPath = GetFolder()
If Len(sPath) = 0 Then Exit Sub
sPath = sPath & "\"
On Error Resume Next
'loop through all worksheets
For iWorksheet = 1 To ActiveWorkbook.Worksheets.Count
Worksheets(iWorksheet).Activate
'set the filename for the output file
sFilename = sPath & ActiveSheet.Name & ".xlsx"
'copy the active sheet into new workbook
ActiveSheet.Copy
ActiveWorkbook.SaveAs _
Filename:=sFilename, _
FileFormat:=51, _
Password:="", _
CreateBackup:=False
Windows("ABC.xlsx").Activate
Sheets(Array("Jan", "Feb", "Mar")).Select -- this line is mine
Sheets(Array("Jan", "Feb", "Mar")).Copy Before:=Workbooks( _ -- this line is mine
"*.xlsx").Sheets(3)[/B] ActiveWorkbook.Close -- this line is mine
Next iWorksheet
End Sub
thanks in advance.
Regards.
struf