这里是Image to support explanation。
如果此列中的条目相同,则D列的值将以相同的颜色突出显示。
在这种情况下,对于每个“组”颜色,我应该:
如您在图片中所看到的,当给定的颜色仅出现在两行中时,J
列中的数量是完美的(对于红色和绿色非常适用)。
但是,一旦颜色覆盖多于两行,则总和并不反映所有行的总和,而是一次仅反映两个条目的总和。
这是我为此计算编写的代码:
Sub test()
Dim LastRow As Long, I As Long, j As Long
Dim arr As Variant
Dim Total_Payments As Single
Dim Total_CashBalance As Single
With ThisWorkbook.Worksheets("Master")
'Find Last row of column L
LastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
'Set array starting from row 2 to LastRow of column L
arr = .Range("D2:D" & LastRow)
For I = LBound(arr) To UBound(arr)
If .Range("D" & I).Interior.Pattern <> xlNone Then
For j = LBound(arr) To UBound(arr)
If (.Range("D" & j).Interior.Pattern <> xlNone) And (I <> j) Then
If .Range("D" & I).Interior.Color = .Range("D" & j).Interior.Color Then
.Range("N" & I).Value = "Cell L" & I & " has the same background color with cell/s L" & j
Total_Payments = .Range("E" & I).Value + .Range("E" & j).Value
Range("J" & I).Value = Total_Payments
End If
End If
Next j
End If
Next I
End With
End Sub
如果您能告诉我如何对一组大于2的单元格中的多个单元格进行这项工作,我将非常高兴:)谢谢!