neilcsmith1984
New Member
- Joined
- May 25, 2020
- Messages
- 14
- Office Version
- 2013
- Platform
- Windows
Hi,
I have the below code that hides shapes on my sheet depending on the value in A1.
The value of A1 derives from a formula and when the formula changes the value in A1 the shapes do not adjust accordingly, the code only works when i type a value into cell A1.
Is it possible to change the code to work whenever the formula in A1 changes?
Sub SetVisible()
Dim s1 As Shape, s2 As Shape
Set s1 = Me.Shapes("Rectangle 1")
Set s2 = Me.Shapes("Rectangle 2")
Select Case UCase(Range("A1").Value)
Case "2015"
s1.Visible = msoTrue
s2.Visible = msoFalse
Case "2016"
s1.Visible = msoFalse
s2.Visible = msoTrue
Case "ALL"
s1.Visible = msoTrue
s2.Visible = msoTrue
Case Else
s1.Visible = msoFalse
s2.Visible = msoFalse
End Select
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A1").Address Then SetVisible
End Sub
Thanks
I have the below code that hides shapes on my sheet depending on the value in A1.
The value of A1 derives from a formula and when the formula changes the value in A1 the shapes do not adjust accordingly, the code only works when i type a value into cell A1.
Is it possible to change the code to work whenever the formula in A1 changes?
Sub SetVisible()
Dim s1 As Shape, s2 As Shape
Set s1 = Me.Shapes("Rectangle 1")
Set s2 = Me.Shapes("Rectangle 2")
Select Case UCase(Range("A1").Value)
Case "2015"
s1.Visible = msoTrue
s2.Visible = msoFalse
Case "2016"
s1.Visible = msoFalse
s2.Visible = msoTrue
Case "ALL"
s1.Visible = msoTrue
s2.Visible = msoTrue
Case Else
s1.Visible = msoFalse
s2.Visible = msoFalse
End Select
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A1").Address Then SetVisible
End Sub
Thanks