Color Macro

Altum681

New Member
Joined
Sep 10, 2014
Messages
12
Hello.

I would like to create a macro that says, if the cell color is green, then make the cell value 0. I have figured out ways to change cell color based on value, but not how to turn the code around. Any ideas?

Thanks!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
try to take a look at interior.color
...which won't work if the color is the result of Condition Formatting (in such a case, the OP would need to have his code perform the same relational test that the Conditional Formatting is using and take action if that relational test return True).
 
Upvote 0
Why would he make the cell color green to change the cell value into a number later. If that would be the case, the logical thing would be an if function based on a value immediately.
 
Upvote 0
Why would he make the cell color green to change the cell value into a number later. If that would be the case, the logical thing would be an if function based on a value immediately.
You raise a good point and you are probably right... I just posted what I did because I have a "feeling" about what I think the OP did, that's all).
 
Upvote 0
You raise a good point and you are probably right... I just posted what I did because I have a "feeling" about what I think the OP did, that's all).

The issue is that I have another macro that overwrites the values in the cell periodically, based on the contents of another page. I can't control the original cell values, but it doesn't make the colors change. So as a simple example, if A4=B4, B4 may change, but A4 can always be green. So After importing information into B4 I would run the macro to change A4, and all other green cells, to 0.
 
Upvote 0
You raise a good point and you are probably right... I just posted what I did because I have a "feeling" about what I think the OP did, that's all).

Thank you for pointing that out though, i didn't know that conditional formatting doesn't count as interior color. I hope you understand the last post of Altum681, the explanation confused me.
Altum, could you tell us why or how the cell (i.e A4) is turned green?
 
Upvote 0
The cell is manually turned green. I go through and adjust the cells that I want to always be 0. I update the spreadsheet monthly, and most cells that start green, stay green each month. I just overwrite the "B4" value in the example several times a day for the first week of the month as prices come in. Since there are 20-30 cells that will always be 0, regardless of what price comes in, I am trying to determine an easy way to force them to 0 without manually adjusting all of them.
 
Upvote 0
This is my current code, but it doesn't produce results.

Sub color()

Range("A:A").Select

If ActiveCell.Interior.color = RGB(174, 240, 194) Then
ActiveCell.Value = "0"

Else

End If

End Sub

I could expand this to loop through all cells, this is just starter code.
 
Upvote 0
This is my current code, but it doesn't produce results.
Code:
If ActiveCell.Interior.color = RGB(174, 240, 194) Then
    ActiveCell.Value = "0"

Is RGB(174, 240, 194) the actual RGB color for the green in your cells? If just one number is different by just as little as 1, the color won't match. To be sure, select one of your green cells and execute this line of code in the VB editor's Immediate Window...

? ActiveCell.Interior.Color

Did it print out 12775598 or not?
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,255
Members
448,556
Latest member
peterhess2002

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