Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Positioning a Graphic in a Macro.

Positioning a Graphic in a Macro

Written by Allen Wyatt (last updated July 24, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

Felix is writing a macro to add a graphic to a worksheet. He needs to position the graphic relative to the top-left corner of a particular cell. He wonders how he can place the graphic, within the macro code, so it is just to the right and beneath the upper-left corner of a given cell.

This task is relatively easy to do if you realize that each cell in a worksheet has both a Top and Left property that defines the location of both the top and left edges of the cell. You can adjust those values, slightly, to get the offset that you want, in this manner:

Dim rCell As Range
Set rCell = Range("A2")
With ActiveSheet.Shapes("Picture 1")
    .Top = rCell.Top + 5
    .Left = rCell.Left + 3
End With

Note that after this code is executed the graphic (defined by the name Picture 1) is placed just below the top edge of cell A2 and just to the right of its left edge.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9726) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Positioning a Graphic in a Macro.

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

Resizing Your Table

Need to make your table a different size? It's easy to do, using the same general technique you use when resizing a ...

Discover More

Moving Cell Borders when Sorting

Sort your data and you may be surprised at what Excel does to your formatting. (Some formatting may be moved in the sort ...

Discover More

Can't Edit Org Charts in Word

Word cand other Office applications are often provided with special add-ins that expand what you can do with the ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Capturing a Screen

A picture is worth a thousand words, but getting the picture, particularly a screen shot, into a workbook may seem ...

Discover More

Creating an Organization Chart

Graphics are often added to worksheets to make it easier to understand the data contained in the worksheet. Sometimes, ...

Discover More

Images Pile Up when Filtering

If you have a worksheet that has numerous pictures in a column, you may get an unwanted surprise when you try to filter ...

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

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 + 1?

2022-07-26 11:26:29

J. Woolley

The ListShapes function described in my previous comment has been overhauled to correctly process grouped shapes and linked formulas.
See https://excelribbon.tips.net/T009264_Finding_and_Replacing_in_Text_Boxes.html
The following columns are now returned for each shape:
Range, Group, Type, Shape Name, Link Formula, Macro Name, Hyperink Address
An option has been added to list each shape's text in a final column labeled Shape Text:
=ListShapes([AllSheets],[SkipHeader],[IncludeText])
The SpillArray function has also been updated to correct a potential error when sheets are inserted or rearranged.
See https://sites.google.com/view/MyExcelToolbox/


2022-01-18 11:29:13

J. Woolley

@Michael Simons
This macro will put an "X" in each picture/shape's top-left cell, then delete the picture/shape:

Sub ShapeX()
For Each s In ActiveSheet.Shapes
s.TopLeftCell.Value = "X"
s.Delete
Next s
End Sub

My Excel Toolbox includes this dynamic array function:
=ListShapes([AllSheets],[SkipHeader])
This will return the following columns for each shape:
Range, Type, Shape Name, Link Formula, Macro Name, Hyperink Address
In older versions of Excel you can use it with the SpillArray function like this:
=SpillArray(ListShapes([AllSheets],[SkipHeader]))
See https://sites.google.com/view/MyExcelToolbox/


2022-01-17 16:29:39

Michael Simons

Related to Positioning a Graphic in a Macro. Would there be a way of determining the position of a pictures relative to a cell address in Excel VBA? The reason for this, many SAP reports have a graphic that is a hyperlink in SAP, but when exported to Excel. I would like to be able to put a text value (say "X") in the cell under the graphic that will then make the work sheet filterable. If there were only a dozen rows it would be easy. But when there are hundreds or thousands it become s impractical. Was thinking - loop through all pictures, underlying cell value = "X", delete picture. This is a screen shot.
{{fig}]


This Site

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

Newest Tips
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.