I am trying to split a file of 65,000 rows into separate files based on a fund code in column A, and using a fund number in column H to name the file. When running the macro, it is working fine for about 30 files, and then I receive an Overflow error. I am thinking this is because of the large number of rows in the original excel sheet. Is there a workaround to this error?
There are 88 unique fund codes in these 65,000 rows.
Also, as an added bonus, if anyone knows how to automatically confirm the Compatibility Checker when saving each of these files, I would appreciate it. Currently, I have to select confirm every time it saves one of the files.
Thank you!
There are 88 unique fund codes in these 65,000 rows.
Code:
Sub Q28_RUN()
'
Dim i As Integer
Dim j As Integer
Dim fund_code As Variant
Dim fund_number As Variant
'
Workbooks("TEST.xls").Activate
'
Worksheets(1).Range(Cells(2, 1), Cells(2, 8).End(xlDown)).Sort _
key1:=Worksheets(1).Cells(2, 1), Header:=xlNo
'
i = 2
j = 1
fund_code = Worksheets(1).Cells(i, 1)
fund_number = Worksheets(1).Cells(i, 8)
'
Do Until fund_code = ""
'
Workbooks.Add
'
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\Q28_" & fund_number, _
FileFormat:=xlNormal, ReadOnlyRecommended:=False, CreateBackup:=False
'
Workbooks("TEST.xls").Activate
Worksheets(1).Range("A1:H1").Select
Selection.Copy
Workbooks("Q28_" & fund_number & ".xls").Activate
Worksheets(1).Range("A1:H1").Select
ActiveSheet.Paste
'
Workbooks("TEST.xls").Activate
'
Do Until Worksheets(1).Cells(i + j, 1) <> fund_code
'
j = j + 1
'
Loop
'
Worksheets(1).Range(Cells(i, 1), Cells(i + j - 1, 8)).Select
Selection.Copy
Workbooks("Q28_" & fund_number & ".xls").Activate
Worksheets(1).Range(Cells(2, 1), Cells(2 + j - 1, 8)).Select
ActiveSheet.Paste
Workbooks("Q28_" & fund_number & ".xls").Activate
Workbooks("Q28_" & fund_number & ".xls").Save
Workbooks("Q28_" & fund_number & ".xls").Close
'
Workbooks("TEST.xls").Activate
'
i = i + j
j = 1
fund_code = Worksheets(1).Cells(i, 1)
fund_number = Worksheets(1).Cells(i, 8)
'
Loop
'
End Sub
Also, as an added bonus, if anyone knows how to automatically confirm the Compatibility Checker when saving each of these files, I would appreciate it. Currently, I have to select confirm every time it saves one of the files.
Thank you!