Forum Discussion

SONIKA_RAO's avatar
SONIKA_RAO
Copper Contributor
Sep 17, 2020

How to get top 3 employee name who are top scorer in Message Box using VBA

Hi Team..I want to get top 3 Emp Name  along with top 3 bids who has top bids using VBA code. I have written a code to get top 3 bids I can get top 3 bids but not able to get Emp Name in same Msg Box...Please look into the code and help me with Empname who has top bids in the given data.

 

Code:-

Sub Top_Bids()

Dim myrange As range
Dim Top1 As Double, Top2 As Double, Top3 As Double

On Error GoTo leave
Set myrange = Excel.Application.Inputbox(Prompt:="Please select a range to get top 3 value", Title:="Top 3 Bids", Type:=8)
If Application.WorksheetFunction.Count(myrange) > 2 Then

Top1 = Excel.Application.WorksheetFunction.Large(myrange, 1)
Top2 = Excel.Application.WorksheetFunction.Large(myrange, 2)
Top3 = Excel.Application.WorksheetFunction.Large(myrange, 3)
MsgBox " Top1 = " & Top1 & vbNewLine & " Top2 = " & Top2 & vbNewLine & " Top3 = " & Top3, Title:="Top 3 Bids!"

Else

MsgBox "Please Select Atleast 3 Cells to Get Top 3 Value", vbInformation

End If

leave:

End Sub

4 Replies

Resources