Macro for Formatting the fill color of a Cell

tinkermary

New Member
Joined
Dec 12, 2008
Messages
16
I need vb code for filling a cell color if another cell contains a value greater than 0.

For example: If the value in cell B14 is greater than 0 then cell b2 will be filled with Yellow color, otherwise it will not be filled.

I tried creating my own but wasn't sure about the "IF" and "THEN" info.

This seems easy but it isn't working for me. Code is below:

Private Sub CommandButton1_Click()
If Range("b18") > 0 Then
ColorIndex = 10
Pattern = xlSolid
PatternColorIndex = xlAutomatic
End If
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello,

select cell B2, select FORMAT --> CONDITIONAL FORMATTING, change VALUE IS to FORMULA IS and enter

=$B$14>0 as the formula, format as required.

CHange the absolute referrences as required for other cells.
 
Upvote 0

Forum statistics

Threads
1,190,764
Messages
5,982,789
Members
439,797
Latest member
ebeck462

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