在函数公式不能处理的情况下,不妨试着使用VBA程序来处理,其程序代码如下:
Sub GetMax()
Dim i, j, k1, k2
Set mysheet1 = ThisWorkbook.Worksheets("Sheet1")
mysheet1.Range("A1:A1000") = ""
For i = 2 To 1000
k1 = Application.WorksheetFunction.Max(mysheet1.Range(mysheet1.Cells(i, 2), mysheet1.Cells(i, 5))) '获取最大值
k2 = Application.WorksheetFunction.CountIf(mysheet1.Range(mysheet1.Cells(i, 2), mysheet1.Cells(i, 5)), "") '统计空白单元格数量
If k2 = 0 Then '如果空白单元格数为零,则
For j = 2 To 5 '从第二列到第五列
If mysheet1.Cells(i, j) = k1 And mysheet1.Cells(i, 1) <> "" Then '与最大值相同且单元格不为空白
mysheet1.Cells(i, 1) = mysheet1.Cells(i, 1) & "," & mysheet1.Cells(1, j) '把对应单元格的值填入此单元格并加逗号间隔
End If
If mysheet1.Cells(i, j) = k1 And mysheet1.Cells(i, 1) = "" Then
mysheet1.Cells(i, 1) = mysheet1.Cells(1, j)
End If
Next
End If
Next
End Sub
VBA程序代码截图如下:
VBA程序的运行结果如下: