VBA Button to find top candidates from table according to overall score

Pantherlucky

New Member
Joined
Oct 31, 2020
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hey, so I need to create a button in a separate worksheet that shows the top 8 scores from 20 entries in total (which are located in a column named "Total score" in Worskheet 1/my initial worsksheet) alongside the names of the top scorers. Out of the 8 top scores a message needs to pop up such that the top 2 are accepted to Department "A", the next 2 best scores (3,4) are accepted to Department "B" and the 5th best score is accepted to Department "C". For the last 3 of the top scorers (meaning 6,7,8) the message that must be shown is "Back ups".
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Pantherlucky let's get the ball rolling. Now this might generate more questions then answers but we have to start some place. My 1st question is what if there is a tie? This program will just pick the scorer alphabetically. This should start the conversation.

VBA Code:
Sub TopScor()


MsgBox "Top 2 go to Department A " & vbNewLine & Sheets("Worksheet 1").Cells(3, 4) & vbNewLine & Sheets("Worksheet 1").Cells(4, 4)
MsgBox "Top 3 & 4 go to Department B " & vbNewLine & Sheets("Worksheet 1").Cells(5, 4) & vbNewLine & Sheets("Worksheet 1").Cells(6, 4)
MsgBox "5th best score goes to Department C " & vbNewLine & Sheets("Worksheet 1").Cells(7, 4)
MsgBox "The 6, 7 & 8 are Back Ups" & vbNewLine & Sheets("Worksheet 1").Cells(8, 4) & vbNewLine & Sheets("Worksheet 1").Cells(9, 4) & vbNewLine & Sheets("Worksheet 1").Cells(10, 4)

End Sub

20-10-31 rank.xlsx
BCDE
1Score
215Top ScorersTop 10 Total Score
391A115
482BG12
573BR10
664A29
755A38
846A67
937A86
1028A95
1119AV4
12010AZ3
130
140
150
1612
170
180
1910
200
Worksheet 1
Cell Formulas
RangeFormula
D3:D12D3=IF(E3="","",INDEX($A$2:$A$20,AGGREGATE(15,6,(ROW($A$2:$A$20)-ROW($A$2)+1)/($B$2:$B$20=E3),COUNTIF(E$3:E3,E3))))
E3:E12E3=IFERROR(AGGREGATE(14,6,$B$2:$B$20/($B$2:$B$20>0),ROWS(E$3:E3)),"")
 
Upvote 0
Greetings and thanks alot for the help! First of, there is no possibility that two candidates have the same grade (consider that as a given). So i solely need to create a button to scan my initial table or the specific column which includes the grades (let's say the column name is "Grades"), sort it in a descending order (perhaps?) and show the messages as stated above. As I said the specific button needs to be in a separate worksheet.
 
Upvote 0
Hello Panther , Please try this vba code , if it satisfy your requirement. IGNORE - the message box writing, you can manage that I suppose. However, the button for the macro must be created in the sheet where you have your entries, the new sheet (2) will contain the top 8 entries upon clicking the button.
VBA Code:
Sub Macro()
Dim i As Double
Dim j As Double

Dim od As Worksheet
Dim nw As Worksheet

Set od = Sheets("Sheet1")
Set nw = Sheets("Sheet2")

For i = 1 To 8
    j = od.Application.WorksheetFunction.Match(od.Application.WorksheetFunction.Large(Range("b2:b20"), i), Range("b2:b20"), 0)
    nw.Range("a" & i & ":" & "b" & i).Value = od.Range("a" & j + 1 & ":" & "b" & j + 1).Value
Next i
MsgBox " Top 2 are accepted to Department A" & vbNewLine & _
"Next 2 (3,4)are accepted to Department B" & vbNewLine & _
"the 5th best score is accepted to Department C" & vbNewLine & _
"For the last 3 of the top scorers (meaning 6,7,8) Back ups"





End Sub
 
Upvote 0
Solution
Hello Panther , Please try this vba code , if it satisfy your requirement. IGNORE - the message box writing, you can manage that I suppose. However, the button for the macro must be created in the sheet where you have your entries, the new sheet (2) will contain the top 8 entries upon clicking the button.
VBA Code:
Sub Macro()
Dim i As Double
Dim j As Double

Dim od As Worksheet
Dim nw As Worksheet

Set od = Sheets("Sheet1")
Set nw = Sheets("Sheet2")

For i = 1 To 8
    j = od.Application.WorksheetFunction.Match(od.Application.WorksheetFunction.Large(Range("b2:b20"), i), Range("b2:b20"), 0)
    nw.Range("a" & i & ":" & "b" & i).Value = od.Range("a" & j + 1 & ":" & "b" & j + 1).Value
Next i
MsgBox " Top 2 are accepted to Department A" & vbNewLine & _
"Next 2 (3,4)are accepted to Department B" & vbNewLine & _
"the 5th best score is accepted to Department C" & vbNewLine & _
"For the last 3 of the top scorers (meaning 6,7,8) Back ups"





End Sub

[/C
[QUOTE="ER_Neha, post: 5580047, member: 464198"]
Hello Panther , Please try this vba code , if it satisfy your requirement. IGNORE - the message box writing, you can manage that I suppose. However, the button for the macro must be created in the sheet where you have your entries, the new sheet (2) will contain the top 8 entries upon clicking the button.[CODE=vba]
Sub Macro()
Dim i As Double
Dim j As Double

Dim od As Worksheet
Dim nw As Worksheet

Set od = Sheets("Sheet1")
Set nw = Sheets("Sheet2")

For i = 1 To 8
    j = od.Application.WorksheetFunction.Match(od.Application.WorksheetFunction.Large(Range("b2:b20"), i), Range("b2:b20"), 0)
    nw.Range("a" & i & ":" & "b" & i).Value = od.Range("a" & j + 1 & ":" & "b" & j + 1).Value
Next i
MsgBox " Top 2 are accepted to Department A" & vbNewLine & _
"Next 2 (3,4)are accepted to Department B" & vbNewLine & _
"the 5th best score is accepted to Department C" & vbNewLine & _
"For the last 3 of the top scorers (meaning 6,7,8) Back ups"





End Sub
Hello Panther , Please try this vba code , if it satisfy your requirement. IGNORE - the message box writing, you can manage that I suppose. However, the button for the macro must be created in the sheet where you have your entries, the new sheet (2) will contain the top 8 entries upon clicking the button.
VBA Code:
Sub Macro()
Dim i As Double
Dim j As Double

Dim od As Worksheet
Dim nw As Worksheet

Set od = Sheets("Sheet1")
Set nw = Sheets("Sheet2")

For i = 1 To 8
    j = od.Application.WorksheetFunction.Match(od.Application.WorksheetFunction.Large(Range("b2:b20"), i), Range("b2:b20"), 0)
    nw.Range("a" & i & ":" & "b" & i).Value = od.Range("a" & j + 1 & ":" & "b" & j + 1).Value
Next i
MsgBox " Top 2 are accepted to Department A" & vbNewLine & _
"Next 2 (3,4)are accepted to Department B" & vbNewLine & _
"the 5th best score is accepted to Department C" & vbNewLine & _
"For the last 3 of the top scorers (meaning 6,7,8) Back ups"





End Sub

ODE]
[/QUOTE]
Could you guide me through this if you may? Am i suppose to put the "Grades" column on "b"? Also what does does "a" stand for? Finally as far as the message boxes are concerned, the name of the candidate needs to be shown aswell, not only the grades..so these two go together. Thus in another column there should be the corresponding name of the top 8 candidates because it needs to be shown in the message box ( imagine a list of the top 8 candidates with their respective grades along side with their acceptance in one of the above departements)
 
Upvote 0

Pantherlucky ER_Neha's code is very good. But I am getting a feeling you are new to Excel and don't see the end result. So let me show you what it will look like.​


so this would be your initial Worksheet
Rank.xlsm
AB
1ScorerGrades
2A116
3A225
4A320
5A623
6A815
7A919
8AV10
9AZ24
10B230
11B329
12B417
13B518
14BC6
15BE4
16BG3
17BI2
18BK1
19BR11
20BS12
Sheet1


Now when you run that program your second sheet would look like this
Rank.xlsm
AB
1B230
2B329
3A225
4AZ24
5A623
6A320
7A919
8B518
Sheet2


and you would get that pop up
1604292461669.png


Now in order to get that button you are talking about your second sheet would have to look like this
1604292563280.png


In order to get that button you need that Developer tab. Do you have or know how to install that tab? Also do you know how to add VBA code to your Excel Workbook?
 
Upvote 0

Forum statistics

Threads
1,215,237
Messages
6,123,803
Members
449,127
Latest member
Cyko

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