Sub ColorRange() '指定した背景色を集計
Dim Gokei As Long
Dim ColorRange As Range
For Each ColorRange In Range("A2:D9")
If ColorRange.Interior.ColorIndex = 3 Then
Gokei = Gokei + ColorRange
End If
Next ColorRange
MsgBox "赤色のセルの合計値は" & Gokei & "です。"
End Sub
Sub ColorRange02() '支店毎に色分けした合計値を算出します。
Dim Gokei, ColorA, I As Long
Dim ColorRange As Range
For I = 2 To 6 'A支店⇒E支店までループ(2列⇒6列)
Gokei = 0 '合計値を0にする。
ColorA = Cells(16, I).Interior.ColorIndex '支店の色を取得する。(16行名)
For Each ColorRange In Range("B4:G13") '表の範囲をしていします。
If ColorRange.Interior.ColorIndex = ColorA Then
Gokei = Gokei + ColorRange '対象の背景色(支店)の数値を加算します。
End If
Next ColorRange
Cells(17, I) = Gokei '背景色毎(支店)に集計した合計値を17行目の合計金額に代入します。
Next I
End Sub
Sub ColorRange03() '勤務表集計
Dim Gokei, ColorA, I, L As Long
Dim ColorRange As Range
For I = 3 To 12 'NO.1~10をループ
Gokei = 0 '合計値を0にする。
ColorA = Cells(2, "R").Interior.ColorIndex '[R2]のセルの背景色を取得する。
For Each ColorRange In Range("C" & I & ":Q" & I) '表の範囲(行ごと)
If ColorRange.Interior.ColorIndex = ColorA Then
Gokei = Gokei + 1 '個別の休日を加算します。
End If
Next ColorRange
Cells(I, "R") = Gokei '個別の休日の合計日数を代入します。
Next I
'---------------------------------------------------------------------
For L = 13 To 14 ' シフト勤務 A.Bをループ
For I = 3 To 17 '1日~15日をループ
Gokei = 0 '合計値を0にする。
ColorA = Cells(L, "B").Interior.ColorIndex 'シフト勤務のセルの背景色を取得する。
For Each ColorRange In Range(Cells(3, I), Cells(12, I)) '表の範囲(列ごと)
If ColorRange.Interior.ColorIndex = ColorA Then
Gokei = Gokei + 1 '個別のシフト勤務を加算します。
End If
Next ColorRange
Cells(L, I) = Gokei '個別のシフト勤務の合計日数を代入します。
Next I
Next L
End Sub