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

alexfooty

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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,324
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
69
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
53,324
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,426
Messages
5,601,595
Members
414,462
Latest member
StageRiis

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