Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Displaying Images based on a Result.

Displaying Images based on a Result

by Allen Wyatt
(last updated June 3, 2014)

Dave has a large database that he keeps in an Excel workbook. It consists of material samples and uses the VLOOKUP function to generate various forms and reports. Dave wants to include a bitmap image on the form that changes according to one of the variables. For instance, if the form is describing an apple, then Dave wants a picture of an apple to appear; if describing a pear, then a pear should appear; and so on.

This is certainly a challenging task, but it is one that can surprisingly be done without macros. The steps are involved, but not that difficult to perform once you get to it:

  1. On a new worksheet, select a cell (such as cell B4).
  2. Enter the name "apple" into the Name box. This defines the name "apple" to refer to cell B4.
  3. With cell B4 still selected, choose Insert | Picture | From File. Select the picture of the apple and insert it.
  4. Enlarge the width and height of cell B4 so that the picture of the apple is contained entirely within the cell.
  5. Repeat steps 1 through 4 for each of your other pictures, placing each picture in a different cell and naming them according to the contents of the picture. (For the sake of this example, I'll assume that "pear" is cell D4 and "orange" is cell F4.)
  6. On the worksheet that will contain your form, create a formula that will contain the names of the fruit, such as the following formula, which displays "apple," "pear," or "orange," depending on the value in cell G1. (It is important that the formula reference the names exactly as you defined them in step 2 for each fruit's picture. For the sake of this example, I'll assume that you entered this formula in cell A1 of Sheet1.)
  7.      =IF(G1=1,"apple",IF(G1=2,"pear",IF(G1=3,"orange","")))
    
  8. Choose Name from the Insert menu, then choose Define. Excel displays the Define Name dialog box. (See Figure 1.)
  9. Figure 1. The Define Name dialog box.

  10. Replace the contents of the Names In Workbook box with the word "Picture".
  11. Replace the contents of the Refers To box with the following formula:
  12.      =INDIRECT(Sheet1!$A$1)
    
  13. Click the OK button. You've now defined the name "Picture" to contain the formula entered in step 9.
  14. On the worksheet that will contain your form, select the cell where you want the dynamic image to appear.
  15. Choose Insert | Picture | From File. Select and insert a picture (it doesn't matter which one).
  16. Make sure the picture you inserted in step 12 is selected.
  17. In the formula bar, enter the formula =Picture. (This is the name you defined in steps 7 through 10.) The picture should change to reflect whatever fruit is named in cell A1.

Now, whenever the fruit name in cell A1 changes (which is, in turn, based on the value in cell G1), the image will change.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3128) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Displaying Images based on a Result.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Creating a Bibliography from Footnotes

Most scholarly papers need to have both footnotes and a bibliography. The two are closely related, as they provide different ...

Discover More

Default Numbering Format for Endnotes

The default format for endnote numbers is lowercase Roman numerals. If you want the numbers to use a different format, such ...

Discover More

Open Workbooks Don't Display

Have you ever opened a workbook, only to have it not display your worksheet data? This can be very disconcerting, but it ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

MORE EXCELTIPS (MENU)

Locking Callouts to a Graph Location

If you add callouts using the drawing tools in Excel, you may have noticed that they don't always stay where you expect them ...

Discover More

Creating an Organization Chart

The graphics capabilities of Excel are flexible enough that you can use the program to create organization charts. Here's how ...

Discover More

Editing Graphic Objects

Want to change the way that a graphic object appears in your worksheet? You need to edit it, then, using the techniques ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)

This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing
Share