2016-08-16 15 views
0

です。C5:C10の背景色が赤であれば、セルB5:B10のSUM値が必要です。Excel - SUMIF次のセルの色は

C5とC8が赤であるとすると、セルB5 + B8のSUMが必要です。

これらは、私が使用したモジュールです:http://www.exceltrick.com/how_to/sum-cells-based-on-background-color/

これは動作しません:= SUMIF(C5:C10を、 "=" & GetCellColor(C5:C10)= "=" & GetCellColor(A1) ; B5:B10)

ありがとうございます!

EDIT:

GetCellColor

Function GetCellColor(xlRange As Range) 
Dim indRow, indColumn As Long 
Dim arResults() 

Application.Volatile 

If xlRange Is Nothing Then 
    Set xlRange = Application.ThisCell 
End If 

If xlRange.Count > 1 Then 
    ReDim arResults(1 To xlRange.Rows.Count, 1 To xlRange.Columns.Count) 
    For indRow = 1 To xlRange.Rows.Count 
    For indColumn = 1 To xlRange.Columns.Count 
     arResults(indRow, indColumn) = xlRange(indRow, indColumn).Interior.Color 
    Next 
    Next 
GetCellColor = arResults 
Else 
GetCellColor = xlRange.Interior.Color 
End If 
End Function 
+1

UDFを投稿できますか? – Brian

+0

私は同意します。 **あなたの質問を編集する* ** GetCellColor()を追加してください**。 –

答えて

0

あなたが前の列の値を持つ任意の連続した垂直範囲の色を持っていて、唯一の赤の色を探している場合、これは動作します:

Function CountAdjacent(colorRange As Range) As Long 

Dim clr As Variant 
Dim countValue As Long 

For Each clr In colorRange 
    If clr.Interior.color = vbRed Then 
     countValue = Application.WorksheetFunction.Sum(clr.Offset(0, -1).Value, countValue) 
    End If 
Next clr 
CountAdjacent = countValue 

End Function 

タイプ=CountAdjacent(yourColorRange)他のフォーミュラのようにセル内にあります。

+0

ブライアンありがとう! – kivi