我正在尝试使我的代码显示上的msg框全部最大,并且在1 msgBox中最大值旁边的值。如果只有一个但不超过一个,我可以使它工作。提前谢谢。
人:输出: 乔什12 约翰14 凯尔14
消息类似于:“前者是Kyle& John,有14个单位。”或者如果只有1个最大值:“最佳表演者是Josh,有12个单位”这就是我试图把它拼凑在一起的。
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
答案 0 :(得分:0)
用循环中的tMax值收集分类器并将它们放入字符串中。
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."