VBA highest grade per row

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,180
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am trying to get the highest grade per row with VBA.

<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC ;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC ;
}
.tableizer-table th {
background-color: #104E8B ;
color: #FFF ;
font-weight: bold;
}
</style>
<table class="tableizer-table">
<thead><tr class="tableizer-firstrow"><th>English</th><th>A</th><th>B</th><th>C</th><th>A</th><th>F</th><th>A</th><th>B</th></tr></thead><tbody>
<tr><td>Math</td><td>A+</td><td>B</td><td>A</td><td>C</td><td>C+</td><td> </td><td> </td></tr>
<tr><td>Science</td><td>F</td><td>C</td><td>C</td><td>F</td><td>F</td><td> </td><td> </td></tr>
<tr><td>SS</td><td>B+</td><td>B</td><td>C</td><td>D+</td><td>B+</td><td>C</td><td></td></tr>
</tbody></table>

this is the output that I desire,
<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC ;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC ;
}
.tableizer-table th {
background-color: #104E8B ;
color: #FFF ;
font-weight: bold;
}
</style>
<table class="tableizer-table">
<thead><tr class="tableizer-firstrow"><th>A</th></tr></thead><tbody>
<tr><td>A+</td></tr>
<tr><td>C</td></tr>
<tr><td>B+</td></tr>
</tbody></table>

this is the code that I have so far but need help! Thanks in advance.

Code:
Function xscore(r As Range) As String
Dim d As Double
For Each c In r
        Select Case UCase(Trim(c))
            Case "A+": xscore = 0
            Case "A": xscore = 1
            Case "A-": xscore = 2
            Case "B+": xscore = 3
            Case "B": xscore = 4
            Case "B-": xscore = 5
            Case "C+": xscore = 6
            Case "C": xscore = 7
            Case "C-": xscore = 8
            Case "D+": xscore = 9
            Case "D": xscore = 10
            Case "D-": xscore = 11
            Case "F": xscore = 12
    End Select
   d = d + xscore
Next
End Function
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try this,

Code:
Function MAXGRADE(r As Range) As String
Dim SD As Object: Set SD = CreateObject("Scripting.Dictionary")
Dim mn As Integer: mn = 12
Dim cel As Range

SD("A+") = 0
SD("A") = 1
SD("A-") = 2
SD("B+") = 3
SD("B") = 4
SD("B-") = 5
SD("C+") = 6
SD("C") = 7
SD("C-") = 8
SD("D+") = 9
SD("D") = 10
SD("D-") = 11

For Each cel In r
    If SD.exists(cel.Value) Then
        If SD.Item(cel.Value) < mn Then
            mn = SD.Item(cel.Value)
        End If
    End If
Next cel

MAXGRADE = SD.keys()(mn)

End Function
 
Upvote 0
Yes beautiful! Thank you very very much! That did the trick!! Thank you again!
 
Upvote 0
───────────────────░█▓▓▓█░▇▆▅▄▃▂
──────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
─────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
──────────░░░───░█▓▓▓▓▓▓█░▇▆▅▄▃▂ ...
─────────░███░──░█▓▓▓▓▓█░▇▆▅▄▃▂
───────░██░░░██░█▓▓▓▓▓█░▇▆▅▄▃▂
──────░█░░█░░░░██▓▓▓▓▓█░▇▆▅▄▃▂
────░██░░█░░░░░░█▓▓▓▓█░▇▆▅▄▃▂
───░█░░░█░░░░░░░██▓▓▓█░▇▆▅▄▃▂
──░█░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░█░░░█░░░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░█░░░░██░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░░█░░░░░██░░░█▓▓▓█░▇▆▅▄▃▂
─░█░█░░░█░░░░░░███▓▓▓▓█░▇▆▅▄▃▂
░█░░░█░░░██░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░█░░░░█████▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░░█░░░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░█░░░░██░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
─░█░█░░░░░████▓▓▓▓██░▇▆▅▄▃▂
─░█░░█░░░░░░░█▓▓██▓█░▇▆▅▄▃▂
──░█░░██░░░██▓▓█▓▓▓█░▇▆▅▄▃▂
───░██░░███▓▓██▓█▓▓█░▇▆▅▄▃▂
────░██▓▓▓███▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓▓▓▓▓▓█░▇▆▅▄▃▂
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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