How to automatically sort a column?

jaedmar

Board Regular
Joined
Feb 14, 2011
Messages
60
How do I make a column of cells sort in order of lowest to highest as soon as I enter a test score in the next empty cell? Also I want to make sure that the adjacent column with people's names is sorted to coincide with the correct test score.

I want it to sort automatically, without me having to highlight and sort each time.
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
OK well this assumes scores in column B and names in column A. Change the 2 to the column number with the scores (e.g. 5 for column E). Right click the sheet tab, select View Code and paste in

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then
    Application.EnableEvents = False
    Range(Cells(2, 1), Cells(Target.Row, Target.Column)).Sort Key1:=Cells(2, Target.Column), Order1:=xlAscending, _
        Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    Application.EnableEvents = True
End If
End Sub
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650

ADVERTISEMENT

Change 2 to 3.
 

scolty1985

Board Regular
Joined
Sep 16, 2009
Messages
86
i was lookin at this earlier today and trimed the example i found down to the following.

Code:
Columns("C").Sort Key1:=Range("C2"), Order1:=xlAscending, _
        Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

VOG code is probably better but for my purposes this worked for me.
 

jaedmar

Board Regular
Joined
Feb 14, 2011
Messages
60
VoG,
I tried that macro, but couldn't get it to work. Maybe I didn't do it rigtht.
Anyway, I have since changed the sheet a bit. Here is what I have now

Column A_____Column B_____Column C_____Column D_____Column E
--RANK---------NAME----------ID#----------SCORE--------AWARD--

This sheet is automatically populated after names and scores are entered in another sheet. The rank is assigned, but is not listed in numerical order.

What I want to do is to have the rank column automatically adjust to list ranks in order from 1 to x (cells A2 to A a77). I want the entire rows to adjust with the rank, so the correct name, ID#.... stay with the assigned rank.

So, if I adjusted a person's score on the other worksheet affecting a person's ranking, this sheet would automatically adjust all columns based on person's rank in Column A.

Does that make sense?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,509
Messages
5,596,558
Members
414,077
Latest member
ammylar5

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top