VBA Rank

Genetu

New Member
Joined
Apr 20, 2022
Messages
23
Office Version
  1. 2016
Platform
  1. Windows
Asked Question for Mrxel.xlsx
ABCDEFGH
1S.No.NameSexID No.(V.Good) Score(Excellent) ScoreTotalRank
21ZilanFHAC/157/12140141
32MathewFHAC/121/12131141
43MesuedFHAC/102/1292113
54JasonFHAC/101/1255104
65JohnsonMHAC/134/1273104
76AzmeraFHAC/122/128196
87OUSMAN MHAC/132/127077
98AliMHAC/133/121677
109AmenFHAC/135/126069
1110VismosFHAC/136/1223510
Sheet1



Good morning members. I have counted the results of each candidate (Excellent & Very good). When I rank them using VBA (it might be the same with function), the same score with different levels has the same rank. That was good but their level (Excellent & Very good) has made the difference. Look at No. 1&2. Their total is the same but the 1st one has not scored "Excellent" but ranked "First". If I rank based on column "F" the 8th (Ali) will be the first, not correct. Is there any method to consider the value of "Excellent" to rank at first?

I have tried this code:

VBA Code:
 Application.CutCopyMode = False
Dim List As Long
     List = Cells(Rows.Count, 7).End(xlUp).row + 1
    r = 2
    
    Do Until r = List
        Cells(r, 8).Value = Application.WorksheetFunction.Rank(Cells(r, 7).Value, Range("G2:G" & List), 0) 
    r = r + 1
    Loop
ActiveWorkbook.Sheets("Report").Columns("B:H").Sort Key1:=Range("H2"), Order1:=xlAscending, Header:=xlYes
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
This is not primarily an excel question since you need to decide what weighting you give to "excellent" compared to "very good" i.e is "excellent" worth twice the value of "Very Good" or 10 times the Value of "Very good" once you have made that decision, VBa can be programmed to do it. SEE Below!! which assumes the value 10
 
Upvote 0
VBA Code:
Option Explicit
Sub rank()
Dim lr&, i&, rng, rng2
With Worksheets("Report")
    lr = .Cells(Rows.Count, "B").End(xlUp).Row
    rng = .Range("E2:G" & lr).Value
    rng2 = .Range("H2:H" & lr).Value
    For i = 1 To lr - 1
        rng2(i, 1) = rng(i, 3) + rng(i, 2) / 10
    Next
    .Range("H2:H" & lr).Value = rng2
    .Range("B2:H" & lr).Sort Key1:=.Range("H2"), Order1:=xlDescending
    .Range("H2:H" & lr).Value = .Range("A2:A" & lr).Value
End With
End Sub
 
Upvote 0
This is not primarily an excel question since you need to decide what weighting you give to "excellent" compared to "very good" i.e is "excellent" worth twice the value of "Very Good" or 10 times the Value of "Very good" once you have made that decision, VBa can be programmed to do it. SEE Below!! which assumes the value 10
First, asking for an apology. I forgot such an idea and thanks "Offthelip". I will check it and get back after a while.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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