Function ColorFunction(rRange As Range)
Dim rCell As Range, lCol As Long, vResult
For Each rCell In rRange '.SpecialCells(xlCellTypeVisible).Cells
If rCell.Interior.Color = vbGreen And Not Rows(rCell.Row).Hidden Then
vResult = 1 + vResult
End If
Next rCell
ColorFunction = vResult
End Function
Sub test()
Dim lr, x, l, j, myrest, stcol, stcol2
Application.ScreenUpdating = False
lr = Range("F" & Rows.Count).End(xlUp).Row
Range("N17", "XFD" & lr).ClearContents
For x = 17 To lr
Range("N" & x, "XFD" & x).Interior.Pattern = xlNone
If Range("G" & x) >= Range("N11") Then
stcol = Application.Match(Range("G" & x), Range("A11", "XFD11"), 0) + 1
edat = stcol - 1
stcol2 = stcol + Range("M" & x).Value
Do While Year(Cells(11, stcol)) = Range("C2")
Cells(x, stcol).Resize(, Range("M" & x).Value).Interior.Color = RGB(0, 112, 192)
Cells(x, stcol2).Resize(, Range("L" & x)).Interior.Color = vbGreen
stcol = stcol + (Range("M" & x) + Range("L" & x))
stcol2 = stcol2 + (Range("M" & x) + Range("L" & x))
Loop
bdat = Application.Match(Range("F" & x), Range("A11", "XFD11"), 0)
If Not IsError(bdat) Then
Range(Cells(x, bdat), Cells(x, edat)).Interior.Color = vbGreen
Else
Range(Cells(x, 14), Cells(x, edat)).Interior.Color = vbGreen
End If
End If
If Range("G" & x) < Range("N11") Then
myrest = (Range("N11") - Range("G" & x)) Mod (Range("M" & x) + Range("L" & x))
If myrest < Range("M" & x) Then
Cells(x, 14).Resize(, (Range("M" & x)) - myrest).Interior.Color = RGB(0, 112, 192)
Cells(x, 14 + (Range("M" & x)) - myrest).Resize(, Range("L" & x)).Interior.Color = vbGreen
stcol = 14 + (Range("M" & x) - myrest) + Range("L" & x)
stcol2 = stcol + Range("M" & x)
Do While Year(Cells(11, stcol)) = Range("C2")
Cells(x, stcol).Resize(, Range("M" & x)).Interior.Color = RGB(0, 112, 192)
Cells(x, stcol2).Resize(, Range("L" & x)).Interior.Color = vbGreen
stcol = stcol + Range("M" & x) + Range("L" & x)
stcol2 = stcol2 + Range("M" & x) + Range("L" & x)
Loop
Else
Cells(x, 14).Resize(, ((Range("L" & x) + Range("M" & x)) - myrest)).Interior.Color = vbGreen
stcol = (14 + Range("L" & x) + Range("M" & x)) - myrest
stcol2 = stcol + Range("L" & x)
Do While Year(Cells(11, stcol)) = Range("C2")
Cells(x, stcol).Resize(, Range("M" & x)).Interior.Color = RGB(0, 112, 192)
Cells(x, stcol2).Resize(, Range("L" & x)).Interior.Color = vbGreen
stcol = stcol + Range("M" & x) + Range("L" & x)
stcol2 = stcol2 + Range("M" & x) + Range("L" & x)
Loop
End If
End If
Next
Range("NO17", "XFD" & lr).Interior.Pattern = xlNone
Range("NO17", "XFD" & lr).ClearContents
'Add to last row + 2 a count of all Green and format cell and font
Range("N" & lr + 2, "NN" & lr + 2).FormulaR1C1 = "=Colorfunction(R17C:R[-1]C)"
Range("N" & lr + 2, "NN" & lr + 2).Interior.Color = RGB(0, 32, 96)
Range("N" & lr + 2, "NN" & lr + 2).Font.Color = RGB(255, 255, 0)
End Sub
Sub Reset()
Range("N17:NN300").ClearContents
Range("N17").Select
End Sub
Sub Green_is_1()
Range("N17").Select
With Application.FindFormat.Interior
.Color = 65280
End With
Range("N17:NN300").Replace What:="", Replacement:="1", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
End Sub
Bookmarks