Hide shapes based on cell true or false value

shelly468

New Member
Joined
Jun 21, 2023
Messages
5
Office Version
  1. 365
Platform
  1. MacOS
Hello,

Fairly new to VBA so not sure where to start.

I have 20 seperate rectangle shapes and each rectangle either needs to be visible or not visible based on each individual 20 cells true or false statements (essentially one rectangle per cell). The true or false statements are given by a formula.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
@shelly468 Welcome.
Your code will depend very much upon how your data and shapes are structured / named.

Below is a super simple example of where the true/false cells are A1:A20 and there are rectangles are named "Rectangle 1" "Rectangle 2" etc

VBA Code:
Sub RectShow()
Dim Rng As Range
Dim r As Integer
'Range for true and falses
Set Rng = Range("A1:A20")

On Error Resume Next  ' Prevent lack of true false causing error
'loop to set visibility to tue or false as per cells
'Assumes rectanglename suffix =cell row
For r = 1 To 20
    ActiveSheet.Shapes("Rectangle " & r).Visible = Range("A" & r)
Next r
On Error GoTo 0  ' reset error handling to normal
End Sub

Hope that gets you started.
If you further need help then you must try and further illustrate your setup.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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