Hide/Unhide the same shape on any active cell with a specified value

Piaget

New Member
Joined
Jul 19, 2018
Messages
7
I am working with the code to hide or unhide a shape whenever a value 1 is entered on a cell. The range includes from J13:AC166. Using the code below it will take more lines to have all the range included. I know there is a way to optimize it. All shapes are of the same look with different names rt1, rt2, rt3... etc. I am really a new coder here. Any help will be much appreciated.


Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveSheet.Range("E13").Value = 1 Then
ActiveSheet.Shapes("rt1").Visible = True
Else
ActiveSheet.Shapes("rt1").Visible = False
End If

If ActiveSheet.Range("F13").Value = 1 Then
ActiveSheet.Shapes("rt2").Visible = True
Else
ActiveSheet.Shapes("rt2").Visible = False
End If

If ActiveSheet.Range("G13").Value = 1 Then
ActiveSheet.Shapes("rt3").Visible = True
Else
ActiveSheet.Shapes("rt3").Visible = False
End If

If ActiveSheet.Range("H13").Value = 1 Then
ActiveSheet.Shapes("rt4").Visible = True
Else
ActiveSheet.Shapes("rt4").Visible = False
End If

If ActiveSheet.Range("I13").Value = 1 Then
ActiveSheet.Shapes("rt5").Visible = True
Else
ActiveSheet.Shapes("rt5").Visible = False
End If

If ActiveSheet.Range("J13").Value = 1 Then
ActiveSheet.Shapes("rt6").Visible = True
Else
ActiveSheet.Shapes("rt6").Visible = False
End If

...

End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Do you actually have 3912 shapes on your sheet? Maybe is you gave us a description of how your shapes are set up in relation to the applicable ranges, we could offer some more efficient coding.
 
Upvote 0
Thank you for your time JLGWHIZ for responding on my query. You are absolutely correct that I will be having 3912 shape. Same look and content. I just duplicated them one by one. I have no idea on how to manipulate a shape actually that is why I just duplicated them. Each cell in the range has its own shape. Everytime a value 1 is entered in a cell the shape appears other than that value the shape on that cell is hidden. Hope I could have better code than the one I posted. Any comment is welcome.
 
Upvote 0
Is there some purpose for these shapes. Or just cosmetic?
Are you going to assign a script to the shape?
You know we maybe could write a script to enter all your shapes for you if you provide us with details about what your doing with these shapes and where they should be entered and what type shape.
 
Upvote 0
This may help, but I think the questions asked by "My Aswer Is This" could change the requirements

Code:
Dim c As Integer, x as integer
x=1
For c = 5 To 166
    If ActiveSheet.Cells(c, 13).Value = 1 Then
        ActiveSheet.Shapes("rt" & x).Visible = True
        Else
        ActiveSheet.Shapes("rt" & x).Visible = False
    End If
x = x + 1
Next c
 
Last edited:
Upvote 0
Are you really set on doing things this way?
So if the student is present the shape will appear or absent the shape will not appear is that the plan.

Would you be going through all these ranges entering 1

Would you be interested in a approach like this:
If you enter a value of 1 the cell color turns Green

Or something similar

This would just need a few lines of code and no need for 3912 shapes.
 
Upvote 0
Are you really set on doing things this way? Yes. I should not deviate with the form.
So if the student is present the shape will appear or absent the shape will not appear is that the plan. -you are correct.
Would you be going through all these ranges entering 1 - definitely

Would you be interested in a approach like this:

If you enter a value of 1 the cell color turns Green - Nope, the shaded right triangle should appear. really. seriously.

--The odd thing about my code I have to copy all the shaded right triangle to all the cells. which could be heavy i think to handle by the worksheet (?)
--what if it is not the only shape i would like to use. (arrg too many shapes)
---i welcome any comment.
---thank you for your response.
 
Upvote 0
So are you adding the shapes to the cells manually or do you have a script to do this.
If you have a script please show it to me.

And are you putting the shapes in the range
J13:AC166

And does the shape fill the cell completely?

I have a script that would enter a shape into this range with no copy involved.

That's why in previous post I mentioned this.

But I would need to know exactly what type shape and where to enter it.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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