• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Shapes enable/disable

Portucale

Member
Hi,

I have a shape (Layer) which I need to be visible when a specific cell (B26) string is “DTV” otherwise the shape is invisible.

I tried the code below, but it doesn't seem to work, any ideas?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Worksheets("Pre").Range("B26") = "DTV" Then
  ActiveSheet.Shapes("Layer").Visible = False 
  Else
  ActiveSheet.Shapes("Layer").Visible = True
  End If 
End Sub

Any help and All the help is very much appreciated.
 
Shouldn't it be:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Worksheets("Pre").Range("B26") = "DTV" Then
  ActiveSheet.Shapes("Layer").Visible = True
  Else
  ActiveSheet.Shapes("Layer").Visible = False
  End If 
End Sub
 
Hi Hui,
Again many thanks for the tip, but or is to early or I am already to stressed.

I possibly forgot to mention that B26 contents changes according to the user selection of three different ActiveX control Option Buttons.

I enclose a worksheet which I hope clarifies better my predicament.

Thanks
 

Attachments

  • Shape enable_disable.xls
    97 KB · Views: 9
Portucale

Active X buttons won't trigger a Change event. You will need to adapt this to be a data validation list or something like data entry so there is a change which Excel can recognise. Something like the following should get you over the line with a Validation list.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B26")) Is Nothing Then
        If Target.Value = "DTV" Then
            Sheet1.Shapes("Layer").Visible = True
        Else
            Sheet1.Shapes("Layer").Visible = False
        End If
    End If
End Sub

File attached to show workings.

Take care

Smallman
 

Attachments

  • Shape enable_disable1.xls
    99.5 KB · Views: 6
Back
Top