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

Understanding Nonprinting Characters

Even characters that print nothing still take space in your document. Characters such as tabs, spaces, breaks, and the ...

Discover More

Moving Master and Subdocuments

If you need to move master documents or subdocuments from one place to another on your computer, you have to keep in mind ...

Discover More

Viewing Your Work Full-Screen

Want to use the maximum space possible for displaying information on screen? You'll want to learn how to use the ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Using WordArt in Excel

The WordArt program has been available in Office for a long, long time. It allows you to (as the name implies) create art ...

Discover More

Taking a Picture

Excel allows you to capture portions of your worksheet as a picture that you can then use in a variety of other ways. ...

Discover More

Pasting a Graphic to Multiple Worksheets

Do you need to add a logo or other graphic to a bunch of worksheets? Here are a couple of short macros that can make ...

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 two more than 7?

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.