View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Incidental Incidental is offline
external usenet poster
 
Posts: 226
Default automatically sorting

Hi Viki

If you put the code below into the worksheet module you wish to sort
automatically it should work for you, though it will use a sort key of
the column a you can change this easily enough by recording a macro
while you do the sort of sort you require.

Option Explicit
Dim LastRow As Integer
Dim LastCol As String
Dim MyCell As String
Private Sub Worksheet_Change(ByVal Target As Range)

LastRow = [A65535].End(xlUp).Row
LastCol = [A1].End(xlToRight).Address

If Len(LastCol) = 4 Then

MyCell = Mid(LastCol, 2, 1) & LastRow

Else

MyCell = Mid(LastCol, 2, 2) & LastRow

End If

Range("A1", MyCell).Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End Sub


Hope this helps

Steve