Conditional Format Shape with Gradient Fill

greekmac7

New Member
Joined
Jan 27, 2016
Messages
4
Hi everyone,

I am currently battling with a piece of code.

I have a shape named "cutshp".I want it to be either red or green depending on whether the value of a cell (q4) is higher or lower than zero.

I want a particular type of gradient fill and shade of red and green. For some reason I can't get this to work for me:



Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ActiveSheet.Shapes("CustShp")
If Range("q4").Value >= 0 Then
    .Fill.ForeColor.RGB = RGB(209, 40, 46)
    .BackColor.RGB = RGB(157, 30, 35)
    .TwoColorGradient Style:=msoGradientDiagonalUp, Variant:=1
        ElseIf Range("q4").Value <= 0 Then
            .Fill.ForeColor.RGB = RGB(77, 157, 87)
            .BackColor.RGB = RGB(58, 118, 65)
            .TwoColorGradient Style:=msoGradientDiagonalUp, Variant:=1

End If
End With
End Sub


any solutions would be greatly appreciated.

Many thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Adding .Fill to With (and removing from inside the With statement):

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With ActiveSheet.Shapes("CustShp").Fill
        If Range("q4").Value >= 0 Then
            .ForeColor.RGB = RGB(209, 40, 46)
            .BackColor.RGB = RGB(157, 30, 35)
            .TwoColorGradient Style:=msoGradientDiagonalUp, Variant:=1
        ElseIf Range("q4").Value <= 0 Then
            .ForeColor.RGB = RGB(77, 157, 87)
            .BackColor.RGB = RGB(58, 118, 65)
            .TwoColorGradient Style:=msoGradientDiagonalUp, Variant:=1
        
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,358
Members
449,155
Latest member
ravioli44

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