Function to return a picture?

D

Daniel Binns

Does anyone know if there is a way to get a function such as VLOOKUP to
return a picture file instead of text or a number?

I am using VLOOKUP to return text (a name) from a seperate table, dependent
on a value that is inputted by the user - but I also want a vlookup function
to return the correct logo that goes with each name that is returned. As far
as I can tell vlookup just returns the contents of a cell (as specified by
the column index number argument), but I can't figure out how to associate
an image with a cell so that it is "embedded" in the table and can then be
returned by a function - images just seem to float around on the sheet
without being linked to a particular cell. Any ideas??

Thanks

Dan
 
F

Frank Kabel

Hi Dan
a worksheet function cannot achieve this. A function can only return
numbers/text values. In addition pictures are not linkes to specific
cells but a 'floating' above them
Frank
 
M

macropod

Hi Daniel,

Here's a user-defined function you can use to display a picture in a cell:

Function ShowPic(PicFile As String) As Boolean
Dim AC As Range
On Error GoTo Done
Set AC = Application.Caller
ActiveSheet.Shapes.AddPicture PicFile, True, True, AC.Left, AC.Top, 200, 200
ShowPic = True
Exit Function
Done:
ShowPic = False
End Function

This function returns TRUE if the picture is found, false otherwise. It will
put the top left corner of the picture in the top left corner of the cell
containing the formula. You could use it like this:
= ShowPic("ONE.JPG")
Where ONE.JPG is a .jpg file that resides in the current working folder. If
not in the working folder, use the complete path.

If you're not familiar with how to add a user-defined function to your
workbook, check out Excel's help.

Cheers
 

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