Copy the attached Excel 2003 workbook into its own folder and run the macro. Study the code
and you'll see how I've created the series of new workbooks.
The code below can replace what is in the attachment. I reworked it to
eliminate unnecessary lines and steps.
Sub Create_WBSeries()
'create new workbook for each 500 data rows in Sheet1 column A
'name each workbook based on a numbered group, i.e., "2-500.xls", "501-1000.xls", etc.
'Exception: 1st workbook to be named "2-500.xls"
'Workbooks not created if they are found in the destination folder.
'
Dim rowCount As Long, newWbCount As Integer, k As Integer, wbAddedCount As Integer
Dim wbStartRow As Long, tmp As String
Dim isNewWorkbook As Boolean
Dim NewBook As Workbook
Dim wbNames() As String
ReDim wbNames(1)
rowCount = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp) - 1
newWbCount = Application.WorksheetFunction.RoundUp(rowCount / 500, 0)
wbNames(0) = "2-500"
wbStartRow = 501
For k = 1 To newWbCount - 1
ReDim Preserve wbNames(UBound(wbNames) + 1)
wbNames(UBound(wbNames) - 1) = CStr(wbStartRow) & "-" & CStr(wbStartRow + 499)
wbStartRow = wbStartRow + 500
Next
Application.ScreenUpdating = False
For k = 0 To UBound(wbNames) - 1
isNewWorkbook = Dir(ThisWorkbook.Path & "\" & wbNames(k) & ".xls") <> ""
If Not isNewWorkbook Then
Set NewBook = Workbooks.Add
NewBook.SaveAs Filename:=ThisWorkbook.Path & "\" & wbNames(k) & ".xls"
ActiveWindow.Close
wbAddedCount = wbAddedCount + 1
tmp = tmp & wbNames(k) & vbCrLf
End If
Next
Application.ScreenUpdating = True
tmp = wbAddedCount & " new workbooks have been added: " & vbCrLf & tmp & vbCrLf & _
"in the folder " & ThisWorkbook.Path
If wbAddedCount = 0 Then tmp = tmp & vbCrLf & vbCrLf & "All workbooks were created previously."
MsgBox tmp
Set NewBook = Nothing
End Sub
Bookmarks