在单元格数组中按颜色求和

时间:2015-10-16 00:15:17

标签: vba

我试图按颜色执行求和我只需要执行一种颜色并将总和输出到单个单元格。附件是我目前拥有的代码,它似乎没有正确地传递单元格的值。

For j = 1 To nCols
    For i = 1 To nRows

        If Worksheets("LG").Cells(i, j).Interior.ColorIndex = 6 Then

            vResult = ActiveCell.Value
        End If
            vResultf = vResultf + vResult
    Next i
Next j



Worksheets("Function Select").Range("B4").Value = vResultf

1 个答案:

答案 0 :(得分:0)

Dim c As Range, j, i, vResultf 

For j = 1 To nCols
    For i = 1 To nRows
        Set c = Worksheets("LG").Cells(i, j)
        If c.Interior.ColorIndex = 6 Then vResultf = vResultf + c.Value
    Next i
Next j

Worksheets("Function Select").Range("B4").Value = vResultf