Hi,
I made what you said myself but the data had not been moved..they stay
in the initial order, don't move..
Could you help me?
Gary''s Student wrote:
Say we have data in cols A & B like:
Name Score
Curley 8
Shep 88
Moe 5
Larry 100
We would like to have this data automatically sorted anytime a value in cols
A or B has changed. (in this example Larry would automatically move to the
top)
In the worksheet code area install this small event macro:
Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
n = Cells(Rows.Count, "A").End(xlUp).Row
Set r = Range("A1:B" & n)
If Intersect(t, r) Is Nothing Then Exit Sub
Application.EnableEvents = False
r.Sort Key1:=Range("B2"), Order1:=xlDescending, Header:=xlYes
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and use:
1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window
If you save the workbook, the macro will be saved with it.
To remove the macro:
1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm