Change pictures in Excel?

P

petterss

Hi!
I want to change a picture depending of a choice in a cell!
EX: In D3 I have a list (dog, cat and bird) and I want to show a
picture of the choice beside the list!
Can I do that :confused:

Thanks :) !
 
P

petterss

Ken said:
Hi peterss,

Check out John McGimpsey's site...

http://www.mcgimpsey.com/excel/lookuppics.html

Ken Johnson


Hi !
I want to show a picture depending of a choice in a specific cell.
have asked before and I get a link to some exempel, the problem is tha
a get an error message and I dont now what to do (I´m a amateur!).

The link was: http://www.mcgimpsey.com/excel/lookuppics.html

I copy the code to my file, but I get an "error 13 - miss match" al
the time.
Code:
Private Sub Worksheet_Calculate()
Dim oPic As Picture
Me.Pictures.Visible = True
With Range("B41")
For Each oPic In Me.Pictures
If oPic.Name = .Text Then
oPic.Visible = True
oPic.Top = .Top
oPic.Left = .Left
Exit For
End If
Next oPic
End With
End Sub

"oPic.Name" never get the same like ".Text", my pictures have name
like 212,213... but "oPic.Name" is like 103,104...
So when it comes to "Next oPic" it stops!

What should I do? Where is the pictures defind? Whats "Me.Pictures"?

Thank
 
Joined
Nov 8, 2007
Messages
1
Reaction score
0
I came accross a similar problem with the script, it seems to happen if you have "things" on your spreadsheet which are recorded in Me.Pictures but are not acutally pictures; buttons, listboxes etc...

You need to specifically list your pictures, make them invisible, then I used an IF statement to look at the cell containing the picture name and display the relevant pic. Like this:

Private Sub Worksheet_Calculate()
Dim x As Integer
Dim Pics(9) As String 'Holds all the pic names

'Picture 1 and 2 are a listbox and a button, so I want these visible
Sheets(1).Shapes("Picture 1").Visible = True
Sheets(1).Shapes("Picture 2").Visible = True

'These are my pics that I want to hide and display
Sheets(1).Shapes("Picture 3").Visible = False
Sheets(1).Shapes("Picture 4").Visible = False
Sheets(1).Shapes("Picture 5").Visible = False
Sheets(1).Shapes("Picture 6").Visible = False
Sheets(1).Shapes("Picture 7").Visible = False
Sheets(1).Shapes("Picture 8").Visible = False
Sheets(1).Shapes("Picture 9").Visible = False
Sheets(1).Shapes("Picture 10").Visible = False
Sheets(1).Shapes("Picture 11").Visible = False
Sheets(1).Shapes("Picture 12").Visible = False

'Fill the array with your pic names
Pics(0) = "Picture 3"
Pics(1) = "Picture 4"
Pics(2) = "Picture 5"
Pics(3) = "Picture 6"
Pics(4) = "Picture 7"
Pics(5) = "Picture 8"
Pics(6) = "Picture 9"
Pics(7) = "Picture 10"
Pics(8) = "Picture 11"
Pics(9) = "Picture 12"
x = 0

With Range("K1") 'K1 is where I want my pic displayed

Do While x <= 9 'Read and match the contents with your pic
If .Text = Pics(x) Then
Sheets(1).Shapes(Pics(x)).Visible = True
Sheets(1).Shapes(Pics(x)).Top = .Top
Sheets(1).Shapes(Pics(x)).Left = .Left

End If
x = x + 1

Loop
End With

End Sub

Hope this helps,
Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top