LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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

 
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 10:02 AM.

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

About Us

"It's about Microsoft Excel"