How to Split a list?

I need a Macro to split a long list into parts at every 350 rows with each part on a separate sheet.
I have attached two files so you can see an example.
Thanks,
Jimi
Routes-2013-9-24.xlsx
Routes-2013-9-24-Final.xlsx
Jimi ShermanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Try this macro in the attached workbook.

Sub SplitData()
Dim lngLastRow As Long
Dim lngIndex As Long

lngLastRow = Range("A65536").End(xlUp).Row

For lngIndex = 2 To lngLastRow Step 350
    Sheets("Sheet1").Range("A1:F1", "A" & lngIndex & ":F" & lngIndex + 349).Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets(Sheets.Count).Paste
Next
End Sub

Open in new window


BTW your original file would be much smaller if you deleted all or most of the blank rows in Sheet1.
Q-28248378.xlsm
0
Jimi ShermanAuthor Commented:
Hi,
When I run this only sheet2 has 350 rows the other sheets has over 700. I was looking for it to be like the "after" file I attached only 350 rows per sheet or less.
Thanks
0
Steven HarrisPresidentCommented:
Building on MartinLiss' code, try something like:

Option Explicit

Sub SplitData()
Dim lngLastRow As Long
Dim lngIndex As Long

lngLastRow = Range("A65536").End(xlUp).Row

For lngIndex = 2 To lngLastRow Step 350
    Sheets("Sheet1").Range("A1:F1", "A" & lngIndex & ":F" & lngIndex + 349).Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets(Sheets.Count).Paste
    Debug.Print lngIndex & "  " & lngIndex + 349
    Sheets("Sheet1").Range("A2:F351").Delete
Next
End Sub

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Martin LissOlder than dirtCommented:
Sub SplitData()
Dim lngLastRow As Long
Dim lngIndex As Long

lngLastRow = Range("A65536").End(xlUp).Row

For lngIndex = 2 To lngLastRow Step 350
    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets("Sheet1").Range("A1:F1").Copy
    Sheets(Sheets.Count).Paste
    Sheets("Sheet1").Range("A" & lngIndex & ":F" & lngIndex + 349).Copy
    Sheets(Sheets.Count).Range("A2").Select
    Sheets(Sheets.Count).Paste
Next
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jimi ShermanAuthor Commented:
This works perfect!
Thanks
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.  And I'm sorry I didn't notice that the first time.

Marty - MVP 2009 to 2013
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.