Auto sorting

  • Thread starter Thread starter Boffita
  • Start date Start date
B

Boffita

Hi,

I have sorted a column (all data from D8:d44) however now when I add
new data in the next column (d55) it doesn't sort it automatically,
have to sort again. Is there a way of sorting the fields actomaticcal
so that when i add more data, it will automatically sort in accendin
order.

Many thanks in advance

Boffita::confused: :confused: :confused: :confused: :confused
 
First, D55 isn't a different column.

And you didn't say how many columns to sort. I just sorted column D. This
could be disastrous if you have data in columns that should move with the sort.

Rightclick on the worksheet tab that should have this behavior and select view
code.

Paste this in
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRng As Range

With Me
Set myRng = .Range("d8:d" & .Cells(.Rows.Count, "D").Row)
End With

If Intersect(Target, myRng) Is Nothing Then Exit Sub

Application.EnableEvents = False
myRng.Sort key1:=myRng(1), order1:=xlAscending, header:=xlNo
Application.EnableEvents = True

End Sub

It assumes that you have some data in D8:d65536.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 
Back
Top