Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel: show different pix based on cell value

Status
Not open for further replies.

rvmams

Technical User
Jan 28, 2003
22
0
0
GB
Hi,

I need help with Excel on the following:

I would like to insert a picture on a specific cell based on a cell value. In other words:

if b2=1 then on top of A1 there is picture X
if b2=2 then on top of A1 there is picture Y
if b2=3 then on top of A1 there is picture Z

Have been trying for hours now and really could use the help!!!!!

Thanks,

Roger
 
Hi,
Code:
    Select Case [B2]
        Case 1
            fName = PathFile1
        Case 2
            fName = PathFile2
        Case 3
            fName = PathFile3
    End Select
    Set oPic = ActiveSheet.Pictures.Insert(fName)
    With oPic
        .Top = [A1].Top
        .Left = [A1].Left
    End With


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hi,

Thanks for your answer but actually I was hoping to have the pix inside the workbook somewhere. Is there a way to do this?

Thnx,

Roger
 
Thanks for all your help on this really appreciate it!!

Sorry to keep asking questions here but I am pretty much a novice when it comes to VBA in Excel... what would the final code look like? Am a bit confused as to where the code from your last reply fits in.

Thnx (again!!)

Roger
 
To make it a procedure (macro), paste this into a VBA Module -- alt+F11/Insert/Module...
Code:
Sub MovePic()
    With Sheets("Sheet1").Shapes([B2])
        .Copy
        ActiveSheet.Paste
        With Selection
            .Top = [A1].Top
            .Left = [A1].Left
        End With
    End With
End Sub
:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top