VBA wont update when reference cell changes due to a formula

Status
Not open for further replies.

neilcsmith1984

New Member
Joined
May 25, 2020
Messages
14
Office Version
  1. 2013
Platform
  1. 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
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Duplicate 2 Vba codes on one sheet

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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