You can't save it in your personal.xls because it needs to be in the
worksheet module of the workbook that you are using.
Right-click on the sheet tab and select View Code. Select the sheet that
you
want it to work in from the Project window if it is not already selected and
ensure that the left-hand window at the top of the module is saying
Worksheet. Delete everything in the module, it probably says:
*************************************
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
End Sub
**************************************
then copy and paste this macro into the Module:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Change the ranges if required
If Intersect(Target, Range("E2:G13")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Application.ScreenUpdating = False
On Error GoTo GetOut
Range("E14:G14").Copy
Range("E17").PasteSpecial Paste:=xlValues, _
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("E1:G1").Copy Destination:=Range("E16")
Application.CutCopyMode = False
Range("E16:G17").Sort Key1:=Range("E17"), _
Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlLeftToRight
Range("E16").Select
GetOut:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Now when you enter any value in E2:G13 the Macro will kick in and sort the
totals under the table for you. If you enter data anywhere else then
nothing will happen.
The Macro assumes that the names are in Row 1 and the Totals are in Row 14.
If the ranges are not correct the change them but keep the quotation makes
around them.
--
HTH
Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings
(e-mail address removed)
Replace @mailinator.com with @tiscali.co.uk