View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach[_2_] Otto Moehrbach[_2_] is offline
external usenet poster
 
Posts: 1,071
Default Copy rows between two criteria

Something like this perhaps. You didn't provide the logic for which sheet
in which to paste so I just write in "'paste somewhere" for you to fill in.
If you have trouble with that, provide the logic of what goes where and I'll
massage it into the code. HTH Otto
Sub SortEach()
Dim rRoute As Range, rZone As Range
Dim rColA As Range, rRngToSort As Range
Set rRoute = Range("A1")
Set rColA = Range("A1", Range("A" & Rows.Count).End(xlUp))
Do
Set rZone = rColA.Find(What:="Zone Total", After:=rRoute, _
LookIn:=xlValues, LookAt:=xlWhole)
Set rRngToSort = Range(rRoute.Offset(1), rZone.Offset(-1)).Resize(,
4)
rRngToSort.Sort Key1:=rRngToSort(1), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range(rRoute, rZone).Resize(, 4).Copy 'Paste somewhere
Set rRoute = rZone.Offset(1)
Loop Until IsEmpty(rRoute.Value)
End Sub

"bpotter" wrote in message
...
I have a workbook that I want to sort out. At the beginning of the
sort is a route name and at the end of the sort is "Zone Total" each
time. What I want to do is sort all rows between these two rows and
paste the correct routes in a corresponding worksheet.

Example:

Route 104 Data Data Data
Customer
Customer
Customer
Zone Total Data Data Data
Route 105 Data Data Data
Customer
Customer
Customer
Customer
Zone Total Data Data Data

And so on
All rows between route 104 and zone total will go on a sheet and all
rows between 105 and zone total will go on a sheet. It will be the
same routes everytime but with possible different customers. I know
how to do simple loops but I am having trouble starting this. Any help
will be much appreciated.