View Single Post
  #26   Report Post  
Posted to microsoft.public.excel.programming
Howard Howard is offline
external usenet poster
 
Posts: 536
Default Worksheet sorting code/technique advise


if you really want to sort individually then try:



Private Sub Workbook_SheetActivate(ByVal Sh As Object)

Dim MyCol As Variant

Dim i As Integer

Dim LRow As Long



Select Case Sh.Name

Case "Sheet1"

MyCol = Array(4, 7, 1, 8, 12)

Case "Sheet2"

MyCol = Array(2)

Case "Sheet3"

MyCol = Array(1, 4, 7, 8, 12)

End Select



For i = LBound(MyCol) To UBound(MyCol)

LRow = Cells(Rows.Count, MyCol(i)).End(xlUp).Row

Range(Cells(1, MyCol(i)), Cells(LRow, MyCol(i))).Sort _

Key1:=Cells(1, MyCol(i)), Order1:=xlAscending, _

Header:=xlYes

Next

End Sub


Hi Claus,

Yes, Yes that really seems to do the trick. I'll test it some more but that is what I was visualizing as the way it should work.

In response to Garry I made the possible assumption that as long as the columns are sorted individually, perhaps the Ascending/Descending could be specific to each column. Not sure if it's worth the effort, however. Probably falls into the "nice to have, but not necessary" category.

Howard