Hello!
I'm trying to create a spreadsheet that automatically sums values in cells based on their colors.
For example:
I've saved the file as a Macro-Enabled Workbook, but I'm encountering these issues:
in the sheet itself, I have this added:
Then I added a module to that sheet that includes the following:
NOTE: I need this to be done to all 5 sheets in this workbook
I attached the file so you guys can check.
Thank you for your help!
I'm trying to create a spreadsheet that automatically sums values in cells based on their colors.
For example:
- Red cells should be summed together.
- Green cells should be summed together.
- Blue cells should be summed together.
- Yellow cells should be summed together.
I've saved the file as a Macro-Enabled Workbook, but I'm encountering these issues:
- When I try to use the formula, I get an "invalid argument" error.
- The formula disappears when I close and reopen the file."
in the sheet itself, I have this added:
Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A:Q")) Is Nothing Then
ActiveSheet.Calculate
End If
End Sub
Then I added a module to that sheet that includes the following:
Code:
Option Explicit
Function SumColor(MatchColor As Range, sumRange As Range)
Application.Volatile True
Dim cell As Range
Dim myColor As Double
myColor = MatchColor.Cells(1, 1).Interior.Color
For Each cell In sumRange
If cell.Interior.Color = myColor Then
SumColor = SumColor + cell.Value
End If
Next
End Function
NOTE: I need this to be done to all 5 sheets in this workbook
I attached the file so you guys can check.
Thank you for your help!
Attachments
Last edited by a moderator: