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

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or 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  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
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

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


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!
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