View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Dave D-C[_3_] Dave D-C[_3_] is offline
external usenet poster
 
Posts: 176
Default A little variation of conventional sorting

Bill,
Thanks for your earlier approach and code.
At that time I noticed that your code handled, e.g. 7,7, and mine
did't.

I've also noted your revision.
I've never written a recursive routine yet that I didn't simplify
upon further reflection. Also, how about generalizing it to handle
triples and higher? This version is 2 routines instead of 3,
is geralized as to n-tuplets, and incorporates your points.

except
'1. Add ActiveSheet qualifier to Main routine.

Doesn't 'Usedrange' assume 'ActiveSheet.Usedrange'?

Option Explicit
Dim gColl As New Collection, gRng As Range, gRowZ&, gColZ%

' assumes usedrange is n-tuplets only
' puts group# to right
' lists groups to the farther right

Sub Main() ' group related n-tuplets
Dim iRowV&, iRowZ&, iCol%, iColZ%, nGroup%
Set gRng = UsedRange ' original usedrange
' get last row, col
gRowZ = gRng.SpecialCells(xlCellTypeLastCell).Row
gColZ = gRng.SpecialCells(xlCellTypeLastCell).Column
iRowV = 1
Do While iRowV <= gRowZ ' look for group start
If Cells(iRowV, gColZ + 1) = "" Then
nGroup = nGroup + 1 ' start new group
Call AddTuplet(nGroup, iRowV)
iCol = gColZ + 2 + n
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----