johnbrownbaby
New Member
- Joined
- Dec 9, 2015
- Messages
- 38
Hello,
I am attempting to automatically get the sub-totals from each blocks (shown in P11-P13, AB11-AB13, P19-P21 and AB19-AB21) then get the overall total to show up in Column E of the three background color of the cells:
There are 4 blocks of data:
Block 1 runs between F9-O14
Block 2 runs between R9-AA14
Block 3 runs between F17-O22 and
Block 4 runs between R17-AA22
I was given a partial solution to get the total from a block via the code:
Can you help me get the subtotals and the overall total of the different background colors in the spreadsheet?
I am attempting to automatically get the sub-totals from each blocks (shown in P11-P13, AB11-AB13, P19-P21 and AB19-AB21) then get the overall total to show up in Column E of the three background color of the cells:
There are 4 blocks of data:
Block 1 runs between F9-O14
Block 2 runs between R9-AA14
Block 3 runs between F17-O22 and
Block 4 runs between R17-AA22
I was given a partial solution to get the total from a block via the code:
VBA Code:
Option Explicit
Sub ColorTotal()
Application.ScreenUpdating = False
Dim c As Range
Dim rng As Range
Dim i As Long, x As Long
Dim lr As Long, lr2 As Long, lc As Long
lr = Range("D" & Rows.Count).End(xlUp).Row
lr2 = Range("F" & Rows.Count).End(xlUp).Row
lc = Cells(9, Columns.Count).End(xlToLeft).Column
Set rng = Range(Cells(9, 14), Cells(lr2, lc))
For i = 6 To lr
x = 0
For Each c In rng
If c.Interior.ColorIndex = Range("D" & i) Then
x = x + 1
End If
Next c
Range("E" & i) = x
Next i
Application.ScreenUpdating = True
MsgBox "Complete!"
End Sub
Can you help me get the subtotals and the overall total of the different background colors in the spreadsheet?