然后检查
.
我解释的功能是分组的概念,因此宏的名称:)
Option Explicit
Sub GroupBy()
Dim lastRow As Long, i As Long, dict As Scripting.Dictionary, key As String
lastRow = Cells(Rows.Count, 2).End(xlUp).Row
Set dict = New Scripting.Dictionary
For i = 1 To lastRow
key = Cells(i, 2) & Cells(i, 4) & Cells(i, 6) & Cells(i, 8) & Cells(i, 10) & Cells(i, 11)
If dict.Exists(key) Then
dict(key) = dict(key) + Cells(i, 15)
Else
dict.Add key, CInt(Cells(i, 15))
End If
Next
For i = 1 To lastRow
key = Cells(i, 2) & Cells(i, 4) & Cells(i, 6) & Cells(i, 8) & Cells(i, 10) & Cells(i, 11)
'if value is other than 20, color the row with red
If dict(key) <> 20 Then Cells(i, 15).Interior.ColorIndex = 3
Next
End Sub