View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Query during macro run

Try this

Sub SortANdInsert()
Dim i As Long

Application.ScreenUpdating = False
cLastRow = Cells(Rows.Count, "B").End(xlUp).Row
Columns("C:C").Insert Shift:=xlToRight
Range("C2").FormulaR1C1 = "=MID(RC[-1],FIND("" "",RC[-1])+1,999)"
Range("C2").AutoFill Destination:=Range("C2:C" & cLastRow),
Type:=xlFillDefault
Columns("B:F").Sort Key1:=Range("C2"), _
Order1:=xlAscending, _
Key2:=Range("F2"), _
Order2:=xlAscending, _
Header:=xlYes, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
Columns("C:C").Delete Shift:=xlToLeft

For i = cLastRow To 2 Step -1
If Cells(i, "B").Value < Cells(i - 1, "B").Value Then
Cells(i, "B").EntireRow.Insert
' i = i - 1
End If
Next i

Application.ScreenUpdating = True
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"mkingsley " wrote in message
...
Thank to Kevin Knierim for help with the selection criteria on my
backoder report macro. Now that I have all of our reps together, I
want to have the macro query column B (reps name) and insert a blank
row below the name (for all reps), and then sort the sales orders (for
the same reps) by oldest date. And do it for all reps. EXA: Raw Data

Column B Column F
Rep Name SO Date

John Smith 5/21/04
John Smith 5/3/04
John Smith 5/1/04
John Doe 5/21/04
John Doe 5/3/04
John Doe 5/1/04

After macro run:

Column B Column F
Rep Name SO Date

John Smith 5/1/04
John Smith 5/3/04
John Smith 5/21/04

John Doe 5/1/04
John Doe 5/3/04
John Doe 5/21/04


---
Message posted from http://www.ExcelForum.com/