您可以使用 For 循环并将活动(和/或任何其他相关信息)分配给特定于个人的数组。然后使用数组填充电子邮件。
这不是很优雅,但它运行在您提供的示例数据上。您可以使用数组数据(并遍历项目)或使用逗号分隔的字符串让玩家填充电子邮件。
Public Sub ReportToPeople()
Dim i As Integer, j As Integer
Dim arrPlayerX()
Dim arrPlayerY()
Dim arrPlayerZ()
Dim strPlayerX As String
Dim strPlayerY As String
Dim strPlayerZ As String
ReDim arrPlayerX(1 To 1)
ReDim arrPlayerY(1 To 1)
ReDim arrPlayerZ(1 To 1)
' No clue how large your dataset is...
For i = 2 To 100
If Cells(i, 1).Value = vbNullString Then Exit For
Select Case Cells(i, 2).Value
Case "Player X"
Call fArrIncrementAndAdd(arrPlayerX, Cells(i, 3).Value, strPlayerX)
Case "Player Y"
Call fArrIncrementAndAdd(arrPlayerY, Cells(i, 3).Value, strPlayerY)
Case "Player Z"
Call fArrIncrementAndAdd(arrPlayerZ, Cells(i, 3).Value, strPlayerZ)
End Select
Next i
Call MsgBox(strPlayerX) 'or use Debug.Print strPlayerX
End Sub
Public Function fArrIncrementAndAdd(ByRef arrTheArray, ByVal strValueToAdd, ByRef strWholeString)
Dim c As Integer
c = UBound(arrTheArray)
If arrTheArray(c) <> vbNullString Then ReDim Preserve arrTheArray(1 To (c + 1))
arrTheArray(c) = strValueToAdd
strWholeString = strWholeString & "," & strValueToAdd
If UBound(arrTheArray) = 1 Then strWholeString = Replace(strWholeString, ",", "") ' removes leading comma on first item
End Function