Good Morning
Task:
Color set of cells, and then sum cells in active column, based on background of cell, then output to specific location.
I found a set of functions that allow me to Count and Sum Cells, based on Color.
I have set up the functions and confirmed they work separately.
Unfortunately, I cannot get everything to now play nice in my userform. I have tried a few configurations, but to no avail.
Here is the code
Here is the code for the functions, just in case
The issue seems to be in this line.
When calling this function in the spreadsheet itself, it would look like this
All help is appreciated.
Thanks
Task:
Color set of cells, and then sum cells in active column, based on background of cell, then output to specific location.
I found a set of functions that allow me to Count and Sum Cells, based on Color.
I have set up the functions and confirmed they work separately.
Unfortunately, I cannot get everything to now play nice in my userform. I have tried a few configurations, but to no avail.
Here is the code
Code:
Dim A1 As Range
Set A1 = Range("A1")
If CheckBox1.Value = True Then
StatTotal = AutoRedist.ComboBox1.Text
Cells.Find(What:=StatTotal, after:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, searchdirection:=xlNext, MatchCase:=False _
, SearchFormat:=True).Activate
RStat = SumByColor(A1, (ActiveCell.Column))
Cells(lastRow, ActiveCell.Column).Offset(1, 0).Value = RStat
ElseIf ...
Code:
Function SumByColor(CellColor As Range, rRange As Range)
Dim cSum As Long
Dim ColIndex As Integer
ColIndex = CellColor.Interior.ColorIndex
For Each cl In rRange
If cl.Interior.ColorIndex = ColIndex Then
cSum = WorksheetFunction.Sum(cl, cSum)
End If
Next cl
SumByColor = cSum
End Function
Function CountByColor(CellColor As Range, CountRange As Range)
Dim ICol As Integer
Dim TCell As Range
ICol = CellColor.Interior.ColorIndex
For Each TCell In CountRange
If ICol = TCell.Interior.ColorIndex Then
CountByColor = CountByColor + 1
End If
Next TCell
End Function
Code:
RStat = SumByColor(A1, (ActiveCell.Column))
Code:
=SumByColor(A1,D:D)
Thanks