How to Resize All Selected Pictures to Fit Cells in Excel

This post will guide you how to resize all selected pictures to fit cell size with VBA Macro in Excel. How do I resize multiple pictures to cell size in Excel.

Resize Multiple Pictures to Fit Cell Size


Assuming that you have inserted multiple pictures into your current worksheet, and you want to resize all selected pictures to fit into the size of the cells. How to do it. You can try to use an Excel VBA Macro to resize multiple selected pictures to fit cell size in your worksheet. Just do the following steps:

#1 select multiple pictures that you want to resize it to fit cell size.

resize all pictures to fit cell1

#2 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1

#3 then the “Visual Basic Editor” window will appear.

#4 click “Insert” ->”Module” to create a new module.

convert column number to letter3

#5 paste the below VBA code into the code (get from here) window. Then clicking “Save” button.

resize all pictures to fit cell2

Public Sub FitMultipleSelectedPics()
    Dim i As Long

    For i = 1 To Selection.Count
        FitIndividualPic Selection(i)
    Next i
End Sub

Public Sub FitIndividualPic(pic As Object)
    Dim PicWtoHRatio As Single
    Dim CellWtoHRatio As Single
    Dim Gap As Single
    Gap = 3
    With pic
        PicWtoHRatio = (.Width / .Height)
    End With

    With pic.TopLeftCell
        CellWtoHRatio = .Width / .RowHeight
     End With

    Select Case PicWtoHRatio / CellWtoHRatio
        Case Is > 1
            With pic
                .Width = .TopLeftCell.Width - Gap
                .Height = .Width / PicWtoHRatio - Gap
            End With
        Case Else

            With pic
                .Height = .TopLeftCell.RowHeight - Gap
                .Width = .Height * PicWtoHRatio - Gap
            End With
    End Select

    With pic
        .Top = .TopLeftCell.Top + Gap
        .Left = .TopLeftCell.Left + Gap
    End With
End Sub

#6 back to the current worksheet, then run the above excel macro. Click Run button.

resize all pictures to fit cell3

#7 Let’s see the last result:

resize all pictures to fit cell4

You will see that all selected pictures have been resized to fit into cell size.

Video: Resize Pictures to Fit Cell Size

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar