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

alexfooty

Board Regular
Joined
Dec 30, 2018
Messages
74
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.
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,574
Office Version
  1. 365
Platform
  1. Windows
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
 

alexfooty

Board Regular
Joined
Dec 30, 2018
Messages
74
Office Version
  1. 2016
Platform
  1. Windows
Fluff - thank you so much for your quick reply which works perfectly - exactly what I needed.
Many thanks
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,574
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,650
Messages
5,626,084
Members
416,161
Latest member
David1966Lewis

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