Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Query during macro run

Thank to Kevin Knierim for help with the selection criteria on m
backoder report macro. Now that I have all of our reps together,
want to have the macro query column B (reps name) and insert a blan
row below the name (for all reps), and then sort the sales orders (fo
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/0

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Query during macro run



--

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/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Query during macro run


Code
-------------------
Sub SortAndInsertSpaces()

Dim iRow As Long
Dim strLast As String

Columns("A:H").Select 'Change this to your columns
Range("A1:H7").Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range( _
"F2"), Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase _
:=False, Orientation:=xlTopToBottom
Range("A1").Select

iRow = 2 'Set to your first row of real data
strLast = Range("B" & iRow)
Do Until Range("B" & iRow).Value = ""
If Range("B" & iRow).Value < strLast Then
Range("B" & iRow).EntireRow.Insert
iRow = iRow + 1
End If
strLast = Range("B" & iRow)
iRow = iRow + 1
Loop

End Su
-------------------

Basically, you sort the data first by name then by date, then inser
the rows. The row insert
code simply counts down column B and inserts a new row when the last
value was different
than the current one. I tested this on a small set of data, so I thin
it will work for you once
you make changes to apply to your worksheet (Sort range and star
row).



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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Query rmsmith Excel Discussion (Misc queries) 0 December 14th 09 05:27 AM
Macro Query carla 7 Excel Discussion (Misc queries) 5 July 31st 08 04:07 PM
another macro query - deleting a worksheet within a query DavidHawes Excel Discussion (Misc queries) 2 February 26th 07 10:05 AM
best way to query during macro run mkingsley Excel Programming 1 May 24th 04 07:50 PM
Web Query in Macro buckle Excel Programming 0 August 19th 03 10:01 PM


All times are GMT +1. The time now is 02:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"