Help with hiding shapes with IF statement VBA

rick23

New Member
Joined
Sep 18, 2014
Messages
16
The code below work perfectly if I am in the same worksheet and make the change to the IF statement from cell A1 to change A26 from "whole" or "", but when I put an equal sign in A1 to reference another sheet's cell, then it does not work. Any ideas how to fix this. I have another formula in a different worksheet that changes A1, which then changes A26. Below is my code - thanks in advance</SPAN>

Private Sub Worksheet_Change(ByVal Target As Range)</SPAN>

If Range("A21").Value = "Whole" Then</SPAN>
ActiveSheet.Shapes("Rounded Rectangle 8").Visible = False</SPAN>
ActiveSheet.Shapes("Rounded Rectangle 14").Visible = False</SPAN>
ActiveSheet.Shapes("Rounded Rectangle 16").Visible = False</SPAN>
Else</SPAN>
ActiveSheet.Shapes("Rounded Rectangle 8").Visible = True</SPAN>
ActiveSheet.Shapes("Rounded Rectangle 14").Visible = True</SPAN>
ActiveSheet.Shapes("Rounded Rectangle 16").Visible = True</SPAN>
End If</SPAN>
End Sub</SPAN>
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Amend your change event and worksheet to trigger with a change to the precedent cell for A1.
 
Upvote 0
Amend your change event and worksheet to trigger with a change to the precedent cell for A1.

Thanks alot for the reply. I am sorry, but I am considered a newbie at this stuff. I understand what you are saying by changing the event, but what would the code look like showing precedent for cell A1. Sorry about asking, but again I appreciate that help.
 
Upvote 0
Thanks alot for the reply. I am sorry, but I am considered a newbie at this stuff. I understand what you are saying by changing the event, but what would the code look like showing precedent for cell A1. Sorry about asking, but again I appreciate that help.

Looking at your post some more b/c your precedent cell contains a formula, it may be that you can get the result you want by changing the current code from a worksheet_change event to a worksheet_calculate event. To try this simply change this line:

Private Sub Worksheet_Change(ByVal Target As Range)

to this:

Private Sub Worksheet_Calculate()

and change "Activesheet" to "Me" (w/o the quote marks) everywhere it appears in the code.
 
Upvote 0
Looking at your post some more b/c your precedent cell contains a formula, it may be that you can get the result you want by changing the current code from a worksheet_change event to a worksheet_calculate event. To try this simply change this line:

Private Sub Worksheet_Change(ByVal Target As Range)

to this:

Private Sub Worksheet_Calculate()

and change "Activesheet" to "Me" (w/o the quote marks) everywhere it appears in the code.


Worked like a charm! Thank you so much.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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