+ Reply to Thread
Results 1 to 2 of 2

Making part of a grouped object visible / invisible

  1. #1
    Registered User
    Join Date
    03-16-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    1

    Making part of a grouped object visible / invisible

    Hi,

    I am really new to VBA so any help would really be appreciated.

    I have a grouped object (ITComp) and based on the value in a cell I would like to display either one of the objects or both within the grouping.

    If the certain values (IT or ITC) are not the values in the cell then nothing should be displayed.

    I have written the code below but it doesn't seem to work as I would like. What seems to happen is that after the first time I change the value in the cell the object disappears for good.

    Private Sub Worksheet_Change(ByVal _
    Target As Excel.Range)
    Dim myRange As Range
    On Error Resume Next
    Set myRange = Intersect(Range("DP34"), Target)
    If myRange = "IT" Then
    With ActiveSheet.Shapes("ITComp")
    .GroupItems(1).Visible = True
    .GroupItems(2).Visible = False
    End With
    ElseIf myRange = "ITC" Then
    With ActiveSheet.Shapes("ITComp")
    .GroupItems(1).Visible = True
    .GroupItems(2).Visible = True
    End With
    Else
    With ActiveSheet.Shapes("ITComp")
    .GroupItems(1).Visible = False
    .GroupItems(2).Visible = False
    End With
    End If
    End Sub


    Any ideas what I am doing wrong?

    Thanks

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Making part of a grouped object visible / invisible

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here


    For me it only misbehaves when the target is not cell DP34 as then it executes the first condition regardless due to your choice of error handling, which is simply to carry on.
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1