+ Reply to Thread
Results 1 to 5 of 5

Thread: Selective Autoshape Hiding from data validation

  1. #1
    Forum Contributor
    Join Date
    07-22-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    116

    Selective Autoshape Hiding from data validation

    Hello,

    I am working working on a spread sheet that has 2 auto-shapes. The auto-shapes are labeled a and b. I have a drop down on the sheet that has the values a and b. What i am shooting for here, is that only the autoshape displayed is the same as the dropdown. So drop down to a and only the autoshape a shows and b does not. Also none show when no value is selected or the cell is blank. I am trying if statements in the vba but not sure on the else statements.
    Here is my code:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Range("B4").Value = "A" Or Range("B4").Value = "" Then
            ActiveSheet.Shapes("Rectangle 10").Visible = False
        If Range("B4").Value = "B Or Range("B4").Value = "" Then
            ActiveSheet.Shapes("Rectangle 11").Visible = False
        End If
        End If
    End Sub

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Selective Autoshape Hiding from data validation

    Try this. Your shapes must be named a and b

    
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address <> "$B$4" Then Exit Sub
     
        Select Case Target.Value
        Case "a"
            ActiveSheet.Shapes("b").Visible = False
            ActiveSheet.Shapes("a").Visible = True
        Case "b"
            ActiveSheet.Shapes("a").Visible = False
            ActiveSheet.Shapes("b").Visible = True
        End Select
    End Sub
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Forum Contributor
    Join Date
    07-22-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    116

    Re: Selective Autoshape Hiding from data validation

    Quote Originally Posted by royUK View Post
    Try this. Your shapes must be named a and b

    
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address <> "$B$4" Then Exit Sub
     
        Select Case Target.Value
        Case "a"
            ActiveSheet.Shapes("b").Visible = False
            ActiveSheet.Shapes("a").Visible = True
        Case "b"
            ActiveSheet.Shapes("a").Visible = False
            ActiveSheet.Shapes("b").Visible = True
        End Select
    End Sub

    I tried the code, and both shapes seemed to have vanished from the workbook, i then recreated them, but after putting in the code after adjusting it accordingly to names and what not, if the value of lets say A2 which i have referenced in a test sheet is blank, both boxes should be hidden until data is selected. I have a test sheet i have attached.

    Here is the code i modified it to:

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address <> "$A$2" Then Exit Sub
     
        Select Case Target.Value
        Case "A"
            ActiveSheet.Shapes("B").Visible = False
            ActiveSheet.Shapes("A").Visible = True
        Case "B"
            ActiveSheet.Shapes("A").Visible = False
            ActiveSheet.Shapes("B").Visible = True
        End Select
    End Sub

  4. #4
    Forum Contributor
    Join Date
    07-22-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    116

    Re: Selective Autoshape Hiding from data validation

    Thanks for your help RoyUK, after tweaking a bit, was able to get it to work, I added an addition case "" to run for the cell in reference being blank. And it works like a charm. Thanks again

  5. #5
    Forum Contributor
    Join Date
    07-22-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    116

    Re: Selective Autoshape Hiding from data validation

    I do have a follow up question for this issue. Would the same hold true for having this apply to a command button?

+ 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.2.0