View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Worksheet sorting code/technique advise

Hi Howard,

Am Mon, 5 Aug 2013 16:30:47 -0700 (PDT) schrieb Howard:

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)


with SheetDeactivate you will get a error message. Try another event.
What do you know about the sheet? Do you know the column that will be
sorted? Then you could try:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim MyCol As Integer

Select Case Sh.Name
Case "Sheet1"
MyCol = 1
Case "Sheet2"
MyCol = 2
Case "Sheet3"
MyCol = 4
End Select
Sh.UsedRange.Sort key1:=Cells(1, MyCol), _
order1:=xlAscending, Header:=xlGuess
End Sub


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2