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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Dave Patton

Well-known Member
Joined
Feb 15, 2002
Messages
4,976
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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.
 

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
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.
 

Derek

Well-known Member
Joined
Feb 16, 2002
Messages
1,592
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
 

Forum statistics

Threads
1,144,768
Messages
5,726,181
Members
422,660
Latest member
mrsteele

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
Top