automatically sorting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

does anyone know how to automatically sort in excel? if one column changes
how to link the entire rows together to automatically sort when the numbers
change? Thanks!
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top