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:


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

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!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Jeff Jones · 1 months ago
    how do you know what picture number to use? I tried adding code for b1 - b3 but not sure what picture number to use?
    • To post as a guest, your comment is unpublished.
      crystal · 1 months ago
      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.