Skip to main content

How to center a picture in an Excel cell?

This article will show you a method of moving pictures to the center of cells in an Excel worksheet as below screenshot shown.

Move picture to center of cell with VBA code


Move picture to center of cell with VBA code.

Please do as follows to move pictures to the center of cells in a worksheet in Excel.

1. Open the worksheet contains the pictures you need to center in cells, then press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, please click Insert > Module. Then copy and paste VBA code into the Code window.

VBA code: Move pictures to center of cells in worksheet

Sub CenterPictures()
With ActiveSheet.Shapes("Picture 2")
.Top = Range("A1").Top + (Range("A1").Height - .Height) / 2
.Left = Range("A1").Left + (Range("A1").Width - .Width) / 2
End With
With ActiveSheet.Shapes("Picture 4")
.Top = Range("A2").Top + (Range("A2").Height - .Height) / 2
.Left = Range("A2").Left + (Range("A2").Width - .Width) / 2
End With
With ActiveSheet.Shapes("Picture 6")
.Top = Range("A3").Top + (Range("A3").Height - .Height) / 2
.Left = Range("A3").Left + (Range("A3").Width - .Width) / 2
End With
End Sub

Notes:

1). In the code, Picture 2 will be moved to the center of cell A1, Picture 4 will be moved to cell A2, and Picture 6 will be moved to cell A3.
2). For more pictures you need to move to center of cells, please add this code into the VBA code and change the Picture Name and Cell Address based on your need.
With ActiveSheet.Shapes("Picture name")
.Top = Range("Cell Address").Top + (Range("Cell Address").Height - .Height) / 2
.Left = Range("Cell Address").Left + (Range("Cell Address").Width - .Width) / 2
End With

3. Press the F5 key to run the code.

Then all specified pictures will be moved to the center of certain cells immediately as below screenshot shown.


Related Articles:

Best Office Productivity Tools

Supports Office/Excel 2007-2021 and 365  |  Available in 44 Languages  |  Easy to Uninstall Completely

Popular Features: Find/Highlight/Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns     Move Columns   |   Unhide Columns   |   Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need Is Just A Click Away...

Supercharge Your Excel Skills: Experience Efficiency Like Never Before with Kutools for Excel  (Full-Featured 30-Day Free Trial)

kte tab 201905

60-Day Unconditional Money-Back GuaranteeRead More... Free Download... Purchase... 

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day! (Full-Featured 30-Day Free Trial)
60-Day Unconditional Money-Back GuaranteeRead More... Free Download... Purchase... 
 
Comments (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi crystal,

Just an idea, how about to center a selected image or shape in a cell, so no need to manually type Picture Name and Cell Address in the code?

Thanks.
This comment was minimized by the moderator on the site
Is there a way to use this macro without having to use the Picture name? Perhaps using the file type such as a .jpg or .png?
This comment was minimized by the moderator on the site
Hi Elijah,
It is hard to match images to the corresponding cells using the file type only.
This comment was minimized by the moderator on the site
how do you know what picture number to use? I tried adding code for b1 - b3 but not sure what picture number to use?
This comment was minimized by the moderator on the site
Hi Jeff,
Sorry for the inconvenience.
When selecting a picture, the picture number will be displayed on the Name box in Excel. It is the picture name in the workbook. See the attached image.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations