Hi All,
I need some help with how to transfer data into multiple workbook with header . I have macro which split the data but don't bring the header into workbook 2 and workbook3 and etc and I like to do that please. Below data is little sample but I have 100K of rows and bigger header name.. I just want to bring 8000 rows to each new workbook with same header.. as you can see th macro does that but not able to bring header along with it. thanks for your help!
Example below of the data:
[TABLE="width: 549"]
<colgroup><col span="6"><col></colgroup><tbody>[TR]
[TD]Change Type (Action)[/TD]
[TD]Adjustment Type[/TD]
[TD]Adjustment Code[/TD]
[TD]Transaction Type[/TD]
[TD]Transaction Usage Code[/TD]
[TD]Transaction Type Code[/TD]
[TD]Transaction Number[/TD]
[/TR]
[TR]
[TD]AL[/TD]
[TD]MANUAL[/TD]
[TD]RESTATE-TCV-ACV[/TD]
[TD]MANUAL[/TD]
[TD]R[/TD]
[TD]B[/TD]
[TD="align: right"]2160036703[/TD]
[/TR]
[TR]
[TD]AL[/TD]
[TD]MANUAL[/TD]
[TD]RESTATE-TCV-ACV[/TD]
[TD]MANUAL[/TD]
[TD]R[/TD]
[TD]B[/TD]
[TD="align: right"]2160028613[/TD]
[/TR]
[TR]
[TD]AL[/TD]
[TD]MANUAL[/TD]
[TD]RESTATE-TCV-ACV[/TD]
[TD]MANUAL[/TD]
[TD]R[/TD]
[TD]B[/TD]
[TD="align: right"]2160017970[/TD]
[/TR]
[TR]
[TD]AL[/TD]
[TD]MANUAL[/TD]
[TD]RESTATE-TCV-ACV[/TD]
[TD]MANUAL[/TD]
[TD]R[/TD]
[TD]B[/TD]
[TD="align: right"]2160018550[/TD]
[/TR]
[TR]
[TD]AL[/TD]
[TD]MANUAL[/TD]
[TD]RESTATE-TCV-ACV[/TD]
[TD]MANUAL[/TD]
[TD]R[/TD]
[TD]B[/TD]
[TD="align: right"]2160029053[/TD]
[/TR]
</tbody>[/TABLE]
macro code:
Sub breakfiles()
Dim wb As Workbook
Dim ThisSheet As Worksheet
Dim NumOfColumns As Integer
Dim RangeToCopy As Range
Dim WorkbookCounter As Integer
Dim RowsInFile
Dim Prefix As String
'Const header_Row = 1
Application.ScreenUpdating = False
'Initialize data
Set ThisSheet = ThisWorkbook.ActiveSheet
NumOfColumns = ThisSheet.UsedRange.Columns.Count
WorkbookCounter = 1
RowsInFile = 8000 'how many rows (incl. header) in new files?
Prefix = "test" 'prefix of the file name
For p = 1 To ThisSheet.UsedRange.Rows.Count Step RowsInFile
Set wb = Workbooks.Add
'Paste the chunk of rows for this file
Set RangeToCopy = ThisSheet.Range(ThisSheet.Cells(p, 1), ThisSheet.Cells(p + RowsInFile - 1, NumOfColumns))
RangeToCopy.Copy wb.Sheets(1).Range("A1")
'Save the new workbook, and close it
wb.SaveAs ThisWorkbook.Path & "" & Prefix & "_" & WorkbookCounter
wb.Close
'Increment file counter
WorkbookCounter = WorkbookCounter + 1
Next p
Application.ScreenUpdating = True
Set wb = Nothing
End Sub
I need some help with how to transfer data into multiple workbook with header . I have macro which split the data but don't bring the header into workbook 2 and workbook3 and etc and I like to do that please. Below data is little sample but I have 100K of rows and bigger header name.. I just want to bring 8000 rows to each new workbook with same header.. as you can see th macro does that but not able to bring header along with it. thanks for your help!
Example below of the data:
[TABLE="width: 549"]
<colgroup><col span="6"><col></colgroup><tbody>[TR]
[TD]Change Type (Action)[/TD]
[TD]Adjustment Type[/TD]
[TD]Adjustment Code[/TD]
[TD]Transaction Type[/TD]
[TD]Transaction Usage Code[/TD]
[TD]Transaction Type Code[/TD]
[TD]Transaction Number[/TD]
[/TR]
[TR]
[TD]AL[/TD]
[TD]MANUAL[/TD]
[TD]RESTATE-TCV-ACV[/TD]
[TD]MANUAL[/TD]
[TD]R[/TD]
[TD]B[/TD]
[TD="align: right"]2160036703[/TD]
[/TR]
[TR]
[TD]AL[/TD]
[TD]MANUAL[/TD]
[TD]RESTATE-TCV-ACV[/TD]
[TD]MANUAL[/TD]
[TD]R[/TD]
[TD]B[/TD]
[TD="align: right"]2160028613[/TD]
[/TR]
[TR]
[TD]AL[/TD]
[TD]MANUAL[/TD]
[TD]RESTATE-TCV-ACV[/TD]
[TD]MANUAL[/TD]
[TD]R[/TD]
[TD]B[/TD]
[TD="align: right"]2160017970[/TD]
[/TR]
[TR]
[TD]AL[/TD]
[TD]MANUAL[/TD]
[TD]RESTATE-TCV-ACV[/TD]
[TD]MANUAL[/TD]
[TD]R[/TD]
[TD]B[/TD]
[TD="align: right"]2160018550[/TD]
[/TR]
[TR]
[TD]AL[/TD]
[TD]MANUAL[/TD]
[TD]RESTATE-TCV-ACV[/TD]
[TD]MANUAL[/TD]
[TD]R[/TD]
[TD]B[/TD]
[TD="align: right"]2160029053[/TD]
[/TR]
</tbody>[/TABLE]
macro code:
Sub breakfiles()
Dim wb As Workbook
Dim ThisSheet As Worksheet
Dim NumOfColumns As Integer
Dim RangeToCopy As Range
Dim WorkbookCounter As Integer
Dim RowsInFile
Dim Prefix As String
'Const header_Row = 1
Application.ScreenUpdating = False
'Initialize data
Set ThisSheet = ThisWorkbook.ActiveSheet
NumOfColumns = ThisSheet.UsedRange.Columns.Count
WorkbookCounter = 1
RowsInFile = 8000 'how many rows (incl. header) in new files?
Prefix = "test" 'prefix of the file name
For p = 1 To ThisSheet.UsedRange.Rows.Count Step RowsInFile
Set wb = Workbooks.Add
'Paste the chunk of rows for this file
Set RangeToCopy = ThisSheet.Range(ThisSheet.Cells(p, 1), ThisSheet.Cells(p + RowsInFile - 1, NumOfColumns))
RangeToCopy.Copy wb.Sheets(1).Range("A1")
'Save the new workbook, and close it
wb.SaveAs ThisWorkbook.Path & "" & Prefix & "_" & WorkbookCounter
wb.Close
'Increment file counter
WorkbookCounter = WorkbookCounter + 1
Next p
Application.ScreenUpdating = True
Set wb = Nothing
End Sub