Sub test() Dim temp_area As Double Dim temp_di_lei As String temp_area = 0 temp_di_lei = "" i = 1 Do While Cells(i, 3).Value <> "" If Cells(i, 3).Value <> Cells(i + 1, 3).Value And temp_area = 0 Then '说明只有一个小班 Cells(i, 7).Value = Cells(i, 2).Value End If If Cells(i, 3).Value = Cells(i + 1, 3).Value Then '说明是相同小班 If Cells(i, 6).Value < Cells(i + 1, 6).Value And Cells(i + 1, 6).Value > temp_area Then temp_area = Cells(i + 1, 6).Value temp_di_lei = Cells(i + 1, 2).Value End If If Cells(i, 6).Value > Cells(i + 1, 6).Value And Cells(i, 6).Value > temp_area Then temp_area = Cells(i, 6).Value temp_di_lei = Cells(i, 2).Value End If End If If Cells(i, 3).Value <> Cells(i + 1, 3).Value And temp_area <> 0 Then '说明当前这一行小班号和下一行小班号不同(相同小班结束) Cells(i, 7).Value = temp_di_lei '输出最大的数据. temp_area = 0 temp_di_lei = "" End If i = i + 1 Loop End Sub