SUM with minus if cell is colored

ride2esc

New Member
Joined
Jun 13, 2015
Messages
16
Hello
Weird question.
If a cell is colored, can the sum calculate with minus?
I am attaching an example.
For example a grocery list, at the bottom I have SUM
But while items are purchased, I color the cells.
Instead of SUM I need it with minus.
Thank you
 

Attachments

  • minus.jpg
    minus.jpg
    46.2 KB · Views: 7

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Have a seperate column to indicate that the item has been purchased.

Use conditional formatting to color the cell.

Use a SUMIF formula to calculate the value where items have been purchased.
 
Upvote 0
Does this help? The Conditionally Formatting rule type is 'Use a formula to determine which cells to format'.
Your cell ranges may be different to mine.

1678105089731.png
 
Upvote 0
Hello
and thank you for trying to help me.
This doesn't help me ;(
I need it with color...
 
Upvote 0
Sadly, there is no event to capture a cell color change unlike capturing a cell value change.

What one can do is check the colours from the Worksheet_SelectionChange event and then update the total.

If a color is changed the event code would need to be called by selecting another cell in the Amounts
column. This will recalculate the total.

This code needs to be placed in the worksheet code module. Right-click on the worksheet tab and select View Code.
You will need to change the "C6:C14" code as appropriate.

Are the number of fruits likely to change?

VBA Code:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngData As Range
Dim indRefColor As Long
Dim rng As Range
Dim dblTotal As Double
Dim rngIntersect As Range

        If Target.CountLarge > 1 Then
            Exit Sub
        End If
        
        Set rngData = Range("C6:C14")
    
        Set rngIntersect = Intersect(rngData, Target)
        
        If Not rngIntersect Is Nothing Then
    
            indRefColor = Cells(1, 1).Interior.Color
        
            For Each rng In rngData.Cells
                If rng.Interior.Color <> indRefColor Then
                    dblTotal = dblTotal + rng.Value
                End If
            Next rng
            
            Range("C15").Value = -dblTotal
     
        End If
     
End Sub
 
Upvote 0
Thank you
With all the respect, can you send me the excel demo with all this VBA code in it?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,487
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top