Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to resize pictures to fit cells in Excel?

Normally inserted pictures floats over cells, and most of time one pictures covers a lot of cells. If a worksheet has a large number of pictures, you may want to put each picture into a single cell. But how to deal with it? Actually, there are several tricky ways to help us resize pictures to fit cells' size quickly.

Resize a selected picture to fit a single cell with VB Macro

Resize inserted pictures to fit cells with Kutools for Excel

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

arrow blue right bubble Resize a selected picture to fit a single cell with VB Macro


We can apply VB macros to resize a selected picture to fit a single cell, but not manually resize a picture's width and height. You can do it with following steps:

Step 1: Insert the pictures in to a worksheet, and select a picture that you will resize it to fit a single cell.

doc-resize-pictures-to-fit-cells1

Step 2: Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

Step 3: Click Insert > Module, and paste the following macro in the Module Window.

VBA: Resize a selected picture to fit a cell.

Public Sub FitPic()
On Error GoTo NOT_SHAPE
Dim PicWtoHRatio As Single
Dim CellWtoHRatio As Single
With Selection
PicWtoHRatio = .Width / .Height
End With
With Selection.TopLeftCell
CellWtoHRatio = .Width / .RowHeight
End With
Select Case PicWtoHRatio / CellWtoHRatio
Case Is > 1
With Selection
.Width = .TopLeftCell.Width
.Height = .Width / PicWtoHRatio
End With
Case Else
With Selection
.Height = .TopLeftCell.RowHeight
.Width = .Height * PicWtoHRatio
End With
End Select
With Selection
.Top = .TopLeftCell.Top
.Left = .TopLeftCell.Left
End With
Exit Sub
NOT_SHAPE:
MsgBox "Select a picture before running this macro."
End Sub

Step 4: Press the F5 key to run this macro.

Step 5: Repeat the steps above to resize other pictures to fit single cell.

Now all inserted pictures are resized and fits into cells. See the following screenshot:

doc-resize-pictures-to-fit-cells2

Note: You can resize only one picture one time. If you select more than one picture one time, a warning dialog box will pop up.


arrow blue right bubble Resize inserted pictures to fit cells with Kutools for Excel

If you have Kutools for Excel installed, you can apply its Import Pictures tool to resize all pictures to fit cells or with fixed height during inserting pictures.

Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 30 days. Get it Now.

Step 1: Select the range cells you want to insert pictures and click the Enterprise >Import/Export > Import Pictures. See the following screenshot:

doc-resize-picture-to-fit-cell-1

Step 2: In the Import Pictures dialog box, select the inserting order in the drop-down list, and click Add button to add pictures you need from file or folder, then click Size button. See screenshot:

doc-resize-picture-to-fit-cell-2

Step 3: Check Matching cell size option. Then click Ok > Import to close dialogs. See screenshot:

doc-resize-picture-to-fit-cell-3

Now you can see the pictures are inserted to fit the cells.

doc-resize-picture-to-fit-cell-4

Note: You also can specify the cell height and width in step 3 to resize the pictures.

If you want to know more about this Import Picture feature, please visit here.


Related Article:

How to resize multiple cells to fit pictures above them quickly in Excel?


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.
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.
    Syed Waqas Gillani · 9 months ago
    Hi..
    perfact solution. But i want that function to work with command button. i need to make a command button to insert and auto resize to cell size. please help.
  • To post as a guest, your comment is unpublished.
    Shripad Lale · 3 years ago
    Brilliant! Works great! Just what I was looking for! Thank you!
  • To post as a guest, your comment is unpublished.
    claus · 3 years ago
    it works if the cells are not merged. unfortunately, I merged some cells and it fits only in the upper left cell which makes the photo very tiny.
  • To post as a guest, your comment is unpublished.
    Harry · 3 years ago
    Hi, I really love this macro that makes images fit cells, it really helped me with some work stuff. But does anyone know how to write this code for applescript? I have to use macs and the apple version of excel, Numbers, only uses applescript.
    Help!
    Many thanks,
    Harry
  • To post as a guest, your comment is unpublished.
    Carol · 3 years ago
    Thanks it did work but I have about 500 pictures so I don't want to do them one at a time - how do I do them all at the same time please?
  • To post as a guest, your comment is unpublished.
    Marcelo · 4 years ago
    Works!!
    But i have one question, i want to fit a img in a range of cells merged, how can i do it?
    • To post as a guest, your comment is unpublished.
      Nick · 2 years ago
      Public Sub FitPic()
      'https://www.extendoffice.com/documents/excel/1060-excel-resize-picture-to-fit-cell.html
      'Slight modification to resize into merged cells
      On Error GoTo NOT_SHAPE
      Dim PicWtoHRatio As Single
      Dim CellWtoHRatio As Single
      With Selection
      PicWtoHRatio = .Width / .Height
      End With
      With Selection.TopLeftCell
      CellWtoHRatio = .MergeArea.Width / .MergeArea.Height
      End With
      Select Case PicWtoHRatio / CellWtoHRatio
      Case Is > 1
      With Selection
      .Width = .TopLeftCell.MergeArea.Width
      .Height = .Width / PicWtoHRatio
      End With
      Case Else
      With Selection
      .Height = .TopLeftCell.MergeArea.Height
      .Width = .Height * PicWtoHRatio
      End With
      End Select
      With Selection
      .Top = .TopLeftCell.MergeArea.Top
      .Left = .TopLeftCell.MergeArea.Left
      .Placement = xlMoveAndSize
      End With
      Exit Sub
      NOT_SHAPE:
      MsgBox "Select a picture before running this macro."
      End Sub
    • To post as a guest, your comment is unpublished.
      Christina · 3 years ago
      [quote name="Marcelo"]Works!!
      But i have one question, i want to fit a img in a range of cells merged, how can i do it?[/quote]

      Marcelo did you get the updated marco for the merged cell? I am trying to do the same thing.

      thanks
  • To post as a guest, your comment is unpublished.
    Monika · 5 years ago
    Thank you this was perfect!!
  • To post as a guest, your comment is unpublished.
    lucy · 5 years ago
    Instructions for Excel
  • To post as a guest, your comment is unpublished.
    Jim Abramczyk · 5 years ago
    FitPic macro noted above is Sweeeeeet!
    I took a bunch of pictures of garage sale items that eventually went to Salvation Army. I documented pictures and values in Excel tax purposes. This macro worked first time! :lol: