VBA highest grade per row

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
966
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
 

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
2,588
Office Version
365, 2019, 2016
Platform
Windows
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
 

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
966
Yes beautiful! Thank you very very much! That did the trick!! Thank you again!
 

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
2,588
Office Version
365, 2019, 2016
Platform
Windows
───────────────────░█▓▓▓█░▇▆▅▄▃▂
──────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
─────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
──────────░░░───░█▓▓▓▓▓▓█░▇▆▅▄▃▂ ...
─────────░███░──░█▓▓▓▓▓█░▇▆▅▄▃▂
───────░██░░░██░█▓▓▓▓▓█░▇▆▅▄▃▂
──────░█░░█░░░░██▓▓▓▓▓█░▇▆▅▄▃▂
────░██░░█░░░░░░█▓▓▓▓█░▇▆▅▄▃▂
───░█░░░█░░░░░░░██▓▓▓█░▇▆▅▄▃▂
──░█░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░█░░░█░░░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░█░░░░██░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░░█░░░░░██░░░█▓▓▓█░▇▆▅▄▃▂
─░█░█░░░█░░░░░░███▓▓▓▓█░▇▆▅▄▃▂
░█░░░█░░░██░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░█░░░░█████▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░░█░░░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░█░░░░██░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
─░█░█░░░░░████▓▓▓▓██░▇▆▅▄▃▂
─░█░░█░░░░░░░█▓▓██▓█░▇▆▅▄▃▂
──░█░░██░░░██▓▓█▓▓▓█░▇▆▅▄▃▂
───░██░░███▓▓██▓█▓▓█░▇▆▅▄▃▂
────░██▓▓▓███▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓▓▓▓▓▓█░▇▆▅▄▃▂
 

Forum statistics

Threads
1,082,344
Messages
5,364,812
Members
400,814
Latest member
gangstar67

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top