Excel Insert Image Based on Cell Value: How It Works

How-to basics · Updated November 19, 2026

Yes. In current Microsoft 365 Excel, use the IMAGE function to show a picture from a URL stored in a cell; if a name or code should select the picture, look up its URL first and pass that result to IMAGE. This displays the picture inside the worksheet cell, rather than inserting a separate floating picture object.

What “image based on a cell value” can mean

There are two common interpretations. The cell may contain the image’s web address, in which case an image formula can display it directly. Or the cell may contain a product code, person’s name, or category that determines which image to show. In the second case, a lookup table connects each value to an image URL, and a formula combines the lookup with IMAGE.

For example, a product list might have codes in column A and pictures in column B. A separate reference table can hold each product code and its public image URL. Changing a product code in the list then changes the picture returned by the formula. This is useful for catalogs, asset lists, staff directories, dashboards, and selection forms.

The important limitation is that IMAGE expects an accessible web URL. Typing a local filename such as C:\Photos\mug.jpg or a folder path into a cell does not make it a supported image source. If the pictures exist only on a computer or shared drive, use a different approach, described below.

Display an image from a URL in a cell

Put a direct image URL in a cell, such as A2, and enter the formula below in B2. This assumes A2 contains the HTTPS address of an image that Excel can access without signing in; the result is the image at that address, shown within B2.

=IMAGE(A2,"Product photo",0)

The second argument is alternative text, which can help people using screen readers understand the picture. The third argument controls sizing. With 0, Excel fits the image inside the cell while preserving its proportions. Copy the formula down to show the image for each URL in column A. If you are using a formatted Excel table, entering the formula in a table column typically fills it down as a calculated column.

To make room for the picture, increase the row height and column width. The picture is displayed in the cell, so a very small cell will produce a very small image even when the source file is large. Keep the URL in a separate column if you want to inspect or edit the source easily.

Choose an image from a code or name

For a value-driven image list, set up a lookup table. For example, put the selected product code in A2, product codes in E2:E4, and the corresponding direct image URLs in F2:F4. With Microsoft 365 or Excel 2021 or later, use XLOOKUP to find the URL and pass it to IMAGE. If A2 contains P-104 and that code is in E3, Excel uses the URL in F3 and displays that image in B2.

With the selected code in A2, codes in E2:E4, and matching direct image URLs in F2:F4, enter this in B2:

=IMAGE(XLOOKUP(A2,$E$2:$E$4,$F$2:$F$4),"Product image",0)

Use exact matching values in the lookup column: an extra space or a different code can prevent a match. If your Excel edition does not include XLOOKUP, a table arranged with codes in the first column and URLs in the second can use VLOOKUP instead. With the same layout and A2 holding the code, this formula returns the matched URL from the second column, then displays its image:

=IMAGE(VLOOKUP(A2,$E$2:$F$4,2,FALSE),"Product image",0)

To avoid an error when a code is missing, add error handling. With the same cells and layout, this formula displays the words “Image unavailable” if the lookup or image formula returns an error; otherwise, it displays the matching picture:

=IFERROR(IMAGE(XLOOKUP(A2,$E$2:$E$4,$F$2:$F$4),"Product image",0),"Image unavailable")

Choose the fallback text to suit the sheet. If a blank selection should leave the output blank, handle that case separately rather than showing an error message. With A2 as the selection and the same lookup table, this formula returns a blank when A2 is empty and otherwise attempts the lookup and displays the image:

=IF(A2="","",IFERROR(IMAGE(XLOOKUP(A2,$E$2:$E$4,$F$2:$F$4),"Product image",0),"Image unavailable"))

How IMAGE sizing and cell placement work

IMAGE has the syntax =IMAGE(source,[alt_text],[sizing],[height],[width]). The source is the URL or a cell reference that contains it. Optional arguments let you provide alternative text and choose how the picture fits. Excel offers four sizing modes:

  • 0 fits the picture inside the cell and preserves its aspect ratio. This is usually the best starting point for product or profile images.
  • 1 fills the cell and preserves the picture’s proportions. Depending on the image and cell shape, some of the image may not fit visibly.
  • 2 displays the picture at its original size, which may extend beyond the available cell area.
  • 3 uses custom height and width values supplied in the next arguments.

With a URL in A2, this custom-size example requests a height of 100 pixels and a width of 150 pixels. The result is a picture sized to those specified dimensions; adjust the row and column dimensions to make the worksheet layout suitable.

=IMAGE(A2,"Product photo",3,100,150)

Unlike an ordinary inserted picture that floats over cells, the output of IMAGE belongs to the cell’s contents. It can be copied, filled down, sorted, and filtered along with other cell data. Sorting a list of product rows therefore keeps each formula with its row, provided you sort the complete data range rather than just one column.

Where the image URL must come from

The URL must point to an image that Excel can retrieve, not merely to a web page that happens to show a picture. A product page address, a link to a sign-in screen, or a sharing page that requires an account may not work as an image source. Use a direct HTTPS image address that is accessible to the workbook’s viewers. Some sites block automated or outside image requests, so a URL that opens in a browser is not guaranteed to display in Excel.

Images may be hosted on a company website, a public image service, or another approved HTTPS location. Consider whether the address will stay stable and whether everyone who opens the workbook is allowed to access it. If a URL includes a temporary access token or points to a private file, the picture may stop working when access expires or the file’s permissions change.

Excel retrieves online images, so availability can depend on an internet connection, the hosting service, and your organization’s security settings. Do not put confidential images on a public host just to make the formula work. Use an organization-approved location and check that the intended workbook users have permission.

Using a dropdown to switch pictures

A dropdown can make a cell-driven image selector easier to use. Put valid product codes in a list, select the input cell, and use Data > Data Validation to create a list whose source is that range. The user selects a code rather than typing it, reducing spelling errors. The lookup-and-image formula can refer to the dropdown cell, so changing the selection changes the displayed picture.

Keep the selectable values and lookup keys consistent. If the dropdown shows product descriptions but the lookup table uses codes, either make the descriptions the lookup keys or add a separate mapping that converts each description to its code. For a large catalog, use an Excel table for the reference data so it is easier to extend and maintain than a set of manually adjusted ranges.

Common problems and practical fixes

  • The formula shows an error or a blocked-image message: confirm the URL is a direct HTTPS image link, can be accessed without a login, and is not blocked by the host or organization policy. Test another known accessible image URL if appropriate.
  • The lookup works but no picture appears: check that the returned value is the image URL, not a product page or local file path. Also check for leading or trailing spaces in the lookup key.
  • The picture looks too small or is cropped: enlarge the row and column, then try sizing mode 0. Mode 1 prioritizes filling the cell and may not show the entire image.
  • The result changes to an error after sharing: recipients may not have internet access or permission to view the host. Confirm access with the intended audience and avoid links that expire.
  • Another Excel version shows an unsupported-function error: the recipient may be using an older version. Check the workbook in the exact Excel versions used by your team before distributing it.

IMAGE formulas versus inserted pictures

Use IMAGE when the picture should respond to a cell’s value and the source can be a suitable web URL. It is formula-driven, so changing the lookup value updates the displayed image without manually replacing a picture. It is also convenient when many rows need consistent image behavior.

For a fixed picture stored on your computer, use Insert > Pictures to add it as a normal picture object. In newer Microsoft 365 builds, Excel also offers in-cell picture placement through Insert > Pictures > Place in Cell. That can keep a picture inside a cell, but inserting a static picture this way does not by itself make the image change when another cell’s value changes. Menu availability can vary by update and platform.

For older workbooks, some users create a linked picture that refers to a changing range, or use VBA to replace picture objects when a selection changes. These approaches involve extra setup and can be less portable than a formula; VBA also requires macros to be enabled and must be saved in a macro-enabled workbook. For most URL-based, selection-driven cases, try IMAGE with a lookup first.

Version and platform considerations

This guidance is for Microsoft Excel for Microsoft 365 on Windows. IMAGE is available in current Microsoft 365 Excel and Excel for the web, but a workbook opened in an older or differently licensed desktop edition may not support it. Confirm feature availability in the Excel versions your recipients use. The formula approach is also available in supported Microsoft 365 Excel for Mac builds; ribbon layout and update timing can differ from Windows.

Excel for the web can calculate and display supported image formulas, but browser, account, and organization policies can affect external image access. If a workbook is intended for multiple platforms, use straightforward formulas and test it in each target environment. A formula that depends on a restricted URL cannot make that URL available to someone who lacks permission.

Frequently Asked Questions

Can Excel insert an image from a filename in a cell?
Not with IMAGE alone. It uses a supported web URL, not a local Windows or Mac file path. For local pictures, insert them as picture objects or consider a managed VBA solution.

Can I show a different image when I change a dropdown?
Yes. Make the dropdown return a code or name, use a lookup to find the matching image URL, and pass that URL to IMAGE. The output updates when the selected value changes, as long as the URL is accessible.

Does IMAGE work with a link to a product webpage?
Usually, the source needs to be a direct link to an image file or an endpoint that returns the image. A normal webpage URL may return HTML instead, so use the image’s direct HTTPS address.

Why does my image show as blocked?
The URL may require authentication, use an unsupported or restricted address, or be blocked by Excel or your organization’s security controls. Check permissions and the URL, and consult your administrator if external content is restricted.

Can I use IMAGE with pictures saved on OneDrive or SharePoint?
It depends on whether the URL Excel receives is a direct, accessible image URL for the people opening the workbook. A sharing link that leads to a sign-in or preview page may not work as the image source. Check access and test the actual URL in the workbook.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.