mlindquist
New Member
- Joined
- Sep 6, 2019
- Messages
- 24
I have a process that I'm populating an excel spreadsheet and then I'm running it through a process from that excel file. I would like to just download the whole population but I can only process about 5,000 at a time. Is there a way to split into separate workbooks based on number of rows. Plus I want the workbook to keep the tabs that are currently in the spreadsheet when copying. Here is what I'm currently running to split within a spreadsheet but then I copy and paste into this other workbook that has all the tabs I need to run a process. Example the tab I want to split by is Data Input and then there are other tabs that I want to keep in the split workbook. Here is a split that I'm currently doing :
What I would like to do is do a split by files (every 3,000 rows) on this one macro enabled spreadsheet that has 5 other tabs on it. That I also want to be included in the split. Right now what I'm doing is I have a workbook then I populate this one tab with the 50,000 rows and then I split into separate worksheets every 3,000 rows. Then I go to each tab (3000 rows) and copy and paste into this other workbook which has other macros that I run after I populate with the data. I might have to do this 50 some times. And then I have to keep track of what I have done by saving a new file.
VBA Code:
Sub SplitWorksheet()
Dim lngLastRow As Long
Dim lngNumberOfRows As Long
Dim lngI As Long
Dim strMainSheetName As String
Dim currSheet As Worksheet
Dim prevSheet As Worksheet
'Number of rows to split among worksheets
lngNumberOfRows = 3000
'Current worksheet in workbook
Set prevSheet = ThisWorkbook.ActiveSheet
'First worksheet name
strMainSheetName = prevSheet.Name
'Number of rows in worksheet
lngLastRow = prevSheet.Cells(Rows.Count, 1).End(xlUp).Row
'Worksheet counter for added worksheets
lngI = 1
While lngLastRow > lngNumberOfRows
Set currSheet = ThisWorkbook.Worksheets.Add
With currSheet
.Move after:=Worksheets(Worksheets.Count)
.Name = strMainSheetName + "(" + CStr(lngI) + ")"
End With
With prevSheet.Rows(lngNumberOfRows + 1 & ":" & lngLastRow).EntireRow
.Cut currSheet.Range("A1")
End With
lngLastRow = currSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set prevSheet = currSheet
lngI = lngI + 1
Wend
End Sub
What I would like to do is do a split by files (every 3,000 rows) on this one macro enabled spreadsheet that has 5 other tabs on it. That I also want to be included in the split. Right now what I'm doing is I have a workbook then I populate this one tab with the 50,000 rows and then I split into separate worksheets every 3,000 rows. Then I go to each tab (3000 rows) and copy and paste into this other workbook which has other macros that I run after I populate with the data. I might have to do this 50 some times. And then I have to keep track of what I have done by saving a new file.