Write a formula depending on cell color

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
Is there a way to write a macro that will find the yellow cells in my worksheet and insert the SUM function?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
On 2002-09-02 09:28, tbardoni wrote:
Is there a way to write a macro that will find the yellow cells in my worksheet and insert the SUM function?

How and what criteria did you use to make the cells color Yellow?

Do you mean the background color?

You could use the same criteria in your macro.

You can search for a User-Defined-Function UDF that can identify the cell's color.
 
Upvote 0
I formatted the cells yellow to highlight the totals, but the list of data is always different and I want a script that will find the yellow formatted cells and insert the SUM function. I'm sure its simple but I've never written any script that dealt with cell color so I'm pretty ignorant.
 
Upvote 0
Hi Tibardoni

You might like to try this macro code. It covers the range A1:G50 , (change as required).
When it finds a yellow cell it sums all cells above it up to the first empty cell

Dim x As Range
For Each cell In Range("A1:G50")
If cell.Interior.ColorIndex = 6 Then
cell.Value = "=sum(" & cell.Offset(-1, 0).Address & ":" & cell.Offset(-1, 0).End(xlUp).Address & ")"
End If
Next
End Sub

Hope this gives you some ideas
regards
Derek
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,853
Members
449,051
Latest member
excelquestion515

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