Consulting

Results 1 to 3 of 3

Thread: Change picture based on cell value

  1. #1

    Change picture based on cell value

    I have a combobox that is populated using the listfillrange. I would like the picture shown in an image control on the worksheet to change based on the value in the combobox combined with the value in cell R27 but I can't seem to get my code to work. Here is what I have:

    Private Sub ComboBox4_Change()
    
    Select Case Me.ComboBox4.Value & Range("r27").Value
        Case "gable0-7"
            Me.Image2.Picture = LoadPicture("x:/excel programs/fbc tile/gable0-7.bmp")
        Case "gable7-27"
            Me.Image2.Picture = LoadPicture("x:/excel programs/fbc tile/gable7-27.bmp")
        Case "gable27-45"
            Me.Image2.Picture = LoadPicture("x:/excel programs/fbc tile/gable27-45.bmp")
        Case "hip7-27"
            Me.Image2.Picture = LoadPicture("x:/excel programs/fbc tile/hip7-27.bmp.bmp")
        Case "monoslope3-10"
            Me.Image2.Picture = LoadPicture("x:/excel programs/fbc tile/mono3-10.bmp")
        Case "monoslope10-30"
            Me.Image2.Picture = LoadPicture("x:/excel programs/fbc tile/mono10-30.bmp")
    End Select
    End Sub

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    How is the Case item split up? e.g "gable0-7" is it "gable" & "0-7", "gable0" & "-7"...etc? are the digits stored as text or numbers? are they part of or a result of a formula?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Mike, I already have an Excel workbook doing this and the "key" to success for me was to include the "Paths" to the Photographs in the Fill range of the Combo box, so by selecting the Name you also select the path. So you don't need the case statement at all.

Posting Permissions

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