VBA - Change color of rectangle shape when column is hidden/unhidden

alexfooty

Board Regular
Joined
Dec 30, 2018
Messages
97
Office Version
  1. 2016
Platform
  1. Windows
Hi
I have a rectangle shape ("Rectangle 6") which runs a simple macro that hides/unhides a column (Col P).

Range("P1").EntireColumn.Hidden = Not Range("P1").EntireColumn.Hidden

What I would like to do is, when the column is hidden the colour of the rectangle shape is green rgb(0, 176, 80)
and when the column is not hidden, the shape colour is red rgb(255, 0. 0).

Any help would be greatly appreciated.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How about
VBA Code:
Sub alexfooty()
   With ActiveSheet.Shapes(Application.Caller).Fill.ForeColor
      .RGB = IIf(.RGB = RGB(255, 0, 0), RGB(0, 176, 80), RGB(255, 0, 0))
   End With
End Sub
 
Upvote 0
Fluff - thank you so much for your quick reply which works perfectly - exactly what I needed.
Many thanks
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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