VBA code for Automatic sorting of cricket points table.

amruthubballi

New Member
Joined
Apr 27, 2017
Messages
15
Ihave created points table with net run rate calculator. The Table is as follows.
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]M[/TD]
[TD]N[/TD]
[TD]O[/TD]
[TD]P[/TD]
[TD]Q[/TD]
[TD]R[/TD]
[TD]S[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]TEAM[/TD]
[TD]PLAYED[/TD]
[TD]WINS[/TD]
[TD]LOSE[/TD]
[TD]NO RESULT[/TD]
[TD]NET RUN RATE[/TD]
[TD]POINTS[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]SRH[/TD]
[TD]14[/TD]
[TD]9[/TD]
[TD]5[/TD]
[TD]0[/TD]
[TD]+0.284[/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]CSK[/TD]
[TD]14[/TD]
[TD]9[/TD]
[TD]5[/TD]
[TD]0[/TD]
[TD]+0.253[/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]KKR[/TD]
[TD]14[/TD]
[TD]8[/TD]
[TD]6[/TD]
[TD]0[/TD]
[TD]-0.070[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]RR[/TD]
[TD]14[/TD]
[TD]7[/TD]
[TD]7[/TD]
[TD]0[/TD]
[TD]-0.250[/TD]
[TD]14[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]MI[/TD]
[TD]14[/TD]
[TD]6[/TD]
[TD]6[/TD]
[TD]2[/TD]
[TD]+0.317[/TD]
[TD]14[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]RCB[/TD]
[TD]14[/TD]
[TD]6[/TD]
[TD]6[/TD]
[TD]2[/TD]
[TD]+0.129[/TD]
[TD]14[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]KXIP[/TD]
[TD]14[/TD]
[TD]6[/TD]
[TD]8[/TD]
[TD]0[/TD]
[TD]-0.502[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]DD[/TD]
[TD]14[/TD]
[TD]5[/TD]
[TD]9[/TD]
[TD]0[/TD]
[TD]-0.222[/TD]
[TD]8[/TD]
[/TR]
</tbody>[/TABLE]

I want tosort the table automatically when I updated score in other cells (which islinked to points table) i.e whenever worksheet changes.
I want tosort all simultaneously
1) in descending of points (Team havingmore points should be first)
2) in descending of wins (if teamshaving same points then team having most no of wins should be first)
3) in descending of net run rate ( Ifteam has same points and same wins then team having high net run rate should befirst.
I have writtenfollowing code but it has error I m not understanding to fully automate theprocess.

Private SubWorksheet_Change(ByVal Target As Range)
Subsortonmorethan3cols()
Range("M4:S12").CurrentRegion.SortKey1:=Range("S4"), order1:=xlDescending, Header:=xlYes,Key2:=Range("O4"), order2:=xlDescending, Header:=xlYes,Key3:=Range("R4"), order3:=xlDescending, Header:=xlYes

End Sub
End Sub
I REQUEST YOU
TO PLEASE HELP ME TO WRITE THE VBA CODE
I HOPE SOME ONE WILL HELP ME TO RESOLVE THIS....

Thank You
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
just this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Range("M4:S12").Sort Key1:=Range("S4"), order1:=xlDescending, Header:=xlYes, Key2:=Range("O4"), order2:=xlDescending, Header:=xlYes, Key3:=Range("R4"), order3:=xlDescending, Header:=xlYes
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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
Back
Top