I am trying to make the msg box on my code display all max and value next to max in 1 msgBox. I can make it work if there is one max only but not more than one. thanks in advance.

Person: Output: josh 12 john 14 kyle 14

Msg something like: "Top per former is Kyle & John with 14 units." or if only 1 max: "Top Performer is Josh with 12 units"

This is what i have trying to piece it together.

Sub Update()

    Dim tMax As Variant
    Dim rngValues As Range
    Dim rngTable As Range
    Dim idx As Long
    '
    Dim msg As String
    Dim n As Long


    Set rngValues = [C21:C32]
    Set rngTables = [A21:A32]

    tMax = Application.WorksheetFunction.Max(rngValues)
    idx = Application.Match(tMax, rngValues, 0)

    'ActiveWorkbook.RefreshAll

    With Range("E17") 'Set Working Day'
    .Value = Date - 1 & " 5:00 PM"
    .NumberFormat = "m/d/yyyy h:mm AM/PM"
    End With

    If Weekday(Date) = 2 Then
    With Range("E17") 'Set Working Day'
    .Value = Date - 3 & " 5:00 PM"
    .NumberFormat = "m/d/yyyy h:mm AM/PM"
    End With
    End If

    With Range("E18")
    .Value = Date & " 5:00 PM"
    .NumberFormat = "m/d/yyyy h:mm AM/PM"
    End With

    Range("C21:C32").Select 'Copy & Paste Stats'
    Selection.Copy

    On Error GoTo Err1 'Date not Found'
    Range("20:20").Find(Date).Select
    ActiveCell.Offset(1, 0).PasteSpecial xlPasteValues

    Err1:
    Range("A6").Select
    Application.CutCopyMode = False


    For i = 21 To 33
           If Cells(i, 3).Value = tMax Then
             n = n + 1
        End If
    Next i


    msg = "Top Triager is " & Application.Index(rngTables, idx) & " with " & tMax & " issues triaged   for the day."
    If n > 1 Then
    msg = msg & " which appeared " & n & " times"
    Else
   msg = msg
End If

MsgBox msg, vbInformation, "Performance:"

'MsgBox "Top Triager is " & Application.Index(rngTables, idx) & " with " & tMax & " issues triaged for the day.", vbInformation, "Performance:"


End Sub
1

There are 1 answers

0
Radek On BEST ANSWER

Collect the triagers with tMax value in loop and put them into the string.

Set rngValues = [C5:C32]
Set rngTables = [A5:A32]

tMax = Application.WorksheetFunction.Max(rngValues)
idx = Application.Match(tMax, rngValues, 0)

For Each IssuesCount In rngValues
    If IssuesCount.Value = tMax Then
        Triagers = Triagers & IIf(Triagers = "", "", " and ") & IssuesCount.Offset(0, -2)
    End If
Next

msg = "Top Triager is " & Triagers & " with " & tMax & " issues triaged   for the day."