Sub d_CellColor_and_Total_in_all_sheets_COUNT()
Dim i As Long, j As Long
Dim k As Integer, l As Integer
Dim LastRow As Long
Dim ws As Object
For Each ws In Worksheets
ws.Select
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Range("B1:B" & LastRow).Select
Selection.Sort Key1:=Range("B1"), Order1:=xlDescending, HEADER:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
For i = LastRow To 1 Step -1
If Range("B" & i).Value >= 0 And Range("B" & i).Value <= 9 Then Range(("A" & i), Range("P" & i)).Interior.ColorIndex = 36
If Range("B" & i).Value >= 10 And Range("B" & i).Value <= 14 Then Range(("A" & i), Range("P" & i)).Interior.ColorIndex = 4
If Range("B" & i).Value >= 15 And Range("B" & i).Value < 20 Then Range(("A" & i), Range("P" & i)).Interior.ColorIndex = 44
If Range("B" & i).Value >= 20 And Range("B" & i).Value < 100 Then Range(("A" & i), Range("P" & i)).Interior.ColorIndex = 3
Range("B1:B" & LastRow).Select
Selection.Sort Key1:=Range("B1"), Order1:=xlDescending, HEADER:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Next i
k = 3
For j = LastRow To 1 Step -1
If Range("B" & j).Interior.Color <> Range("B" & j + 1).Interior.Color Then
Range("B" & j + 1).Select
For l = 1 To k
Selection.EntireRow.Insert
Selection.EntireRow.Clear
Next l
End If
Next j
Range("2:4").Select
Selection.Delete Shift:=xlToup
Dim LR As Long
Dim Area As Range
With ActiveSheet
LR = .Range("J" & .Rows.Count).End(xlUp).Row
If LR = 2 Then
.Range("J4").Formula = "=SUM(J2)"
Else
For Each Area In .Range("J2:J" & LR).SpecialCells(xlCellTypeConstants).Areas
With Area.Resize(1).Offset(Area.Rows.Count + 1)
.Formula = "=SUM(" & Area.Address & ")"
.Offset(0, 1).Formula = "=COUNT(" & Area.Address & ")"
[B][COLOR=Red].Offset(0, 1).Font.ColorIndex = 2[/COLOR][/B]
End With
Next Area
End If
End With
Next
End Sub