Adding a formula to a cell if the cell is a color

nharris

New Member
Joined
Mar 14, 2024
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Is there a way to add a function to a cell if that cell is a certain color?

So if i took these steps:

1. I made A1 "green"
2. I want D14 if it was made "green" to add this value to D14 =SUM(C14*1.0975)

Is this possible?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
You can create a function using VBA to check if the cell is green.

Insert this into a VBA module.
VBA Code:
Function IsCellGreen(cell As Range) As Boolean
    IsCellGreen = (cell.Interior.Color = RGB(0, 255, 0))
End Function

In D14,
Excel Formula:
=IF(IsCellGreen(A1),SUM(C14*1.0975),"")
 
Upvote 0
You can create a function using VBA to check if the cell is green.

Insert this into a VBA module.
VBA Code:
Function IsCellGreen(cell As Range) As Boolean
    IsCellGreen = (cell.Interior.Color = RGB(0, 255, 0))
End Function

In D14,
Excel Formula:
=IF(IsCellGreen(A1),SUM(C14*1.0975),"")
Thanks! I will try it and let you know if it works
 
Upvote 0
doesnt seem to be working. i have attached the pics of the data input that you shared with me to see if I input it correctly
 

Attachments

  • excel3.jpg
    excel3.jpg
    60.3 KB · Views: 1
  • excel1.jpg
    excel1.jpg
    64.7 KB · Views: 1
  • exc3l2.jpg
    exc3l2.jpg
    96.5 KB · Views: 1
Upvote 0
Select the green cell, ctrl + 1 - > Fill -> More colors -> Custom -> Make sure the RGB matches with the ones in VBA code.
 
Last edited:
Upvote 0
is there a way to make the cell auto fill when changing the color to the cell? i have to physically double click the cell and hit enter before it will update the cell
 
Upvote 0
Right-click on the tab name -> View code -> Insert this... See if this works.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A1")) Is Nothing Then
        Application.EnableEvents = False
        Range("A1").Value = Range("A1").Value
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,137
Messages
6,123,254
Members
449,093
Latest member
Vincent Khandagale

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