+ Reply to Thread
Results 1 to 4 of 4

Hiding / unhiding pictures based on cell value

Hybrid View

supern0va Hiding / unhiding pictures... 08-14-2012, 10:52 AM
patel45 Re: Hiding / unhiding... 08-14-2012, 11:43 AM
supern0va Re: Hiding / unhiding... 08-14-2012, 11:56 AM
supern0va Re: Hiding / unhiding... 08-14-2012, 12:00 PM
  1. #1
    Registered User
    Join Date
    02-05-2011
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    56

    Hiding / unhiding pictures based on cell value

    Hi,

    The last few days I've been working on a multiple choice quiz in excel.
    I have a working version that picks questions from a column and answers from another, and presents it to the user. See attached.

    Now I want the questions for chapter 1 to be pictures instead of text. I added some dummy pics in the doc I attached.
    I used this tutorial.
    It is supposed to hide all pictures and then display one on a specified location [U]if[U] that picture's name corresponds to a cell value (which is a vlookup formula).

    But I get an error on the following line
     For Each oPic In Me.Pictures
    Run-time error '13': Type mismatch

    Complete code for that sub:
    (Me.pictures.visible should be false. Is still true in attached doc.)

        Private Sub Worksheet_Calculate()
    
            Dim oPic As Picture
            Me.Pictures.Visible = False
            With Worksheets("Quiz").Range("L2")
                For Each oPic In Me.Pictures
                    If oPic.Name = .Text Then
                        oPic.Visible = True
                        oPic.Top = .Top
                        oPic.Left = .Right
                        Exit For
                    End If
                Next oPic
            End With
        End Sub
    Does anyone see what I'm doing wrong?
    Attached Files Attached Files
    Last edited by supern0va; 08-14-2012 at 10:57 AM. Reason: remark: pics instead of text only for chapter 1!

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Hiding / unhiding pictures based on cell value

    I can't find object pictures, you can try something like
        Private Sub Worksheet_Calculate()
    
            Dim oPic As Shape
            With Worksheets("Quiz").Range("L2")
                For Each oPic In Me.Shapes
                    If oPic.Name = .Text Then
                        oPic.Visible = True
                        oPic.Top = .Top
                        oPic.Left = .Left 'Right
                        Exit For
                    End If
                Next oPic
            End With
        End Sub
    Last edited by patel45; 08-14-2012 at 12:19 PM.

  3. #3
    Registered User
    Join Date
    02-05-2011
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: Hiding / unhiding pictures based on cell value

    Hi Patel,

    Thanks. Yes, .Left instead of .Right solved part of the problem.

    I also tracked down the second part of the problem. There's a type mismatch because not only the jpegs are detected as pictures, but also the start and reset button
    See for yourself.
     Sub Countpics()
    MsgBox Worksheets("Quiz").Pictures.Count
    End Sub
    gives 26 hits: 2 buttons and 24 pictures.

    when I remove those buttons, the code above works fine but the sheet itself is useless. :s

    The reason you didn't see pictures is probably because they were hidden by
     Me.Pictures.Visible = False
    I'm adding an updated version. Care to take another shot?

    Thanks a bunch!
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-05-2011
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: Hiding / unhiding pictures based on cell value

    WHOO! Well that was obvious :p I scrapped the buttons which were ActiveX controls and replaced them with form controls. Flawless victory

+ 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