2015-10-16 65 views
1

我想通過顏色執行求和我只需要這個來執行一種顏色並且將總和輸出到單個單元格。附加的是我目前擁有的代碼,它看起來並沒有正確地攜帶單元格的值。根據單元格陣列中的顏色求和

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 

回答

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 
相關問題