View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default Code to automatically sort a list, each time that a new entry isadded to the bottom of the list

On 13 Apr., 07:04, Mike C wrote:
Hello - I am wondering if anyone could provide me with code that will
re-sort a list, each time a user places a new line at the bottom of
the list.

So, for example, in column A, rows 1-10, I have a list of names, which
are sorted descending. *When a new name is added to row 11, and the
user clicks out off of the cell or presses enter, I am hoping the
column can automatically resort.

Thanks for any suggestions.


Hi Mike

Place the code below in the code sheet of the sheet containing your
list.

Private Sub Worksheet_Change(ByVal Target As Range)
Set isect = Intersect(Target, Range("A:A"))
If Not isect Is Nothing Then
Range("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End If
End Sub

Regards,
Per