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.
#2 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.
#3 then the “Visual Basic Editor” window will appear.
#4 click “Insert” ->”Module” to create a new module.
#5 paste the below VBA code into the code (get from here) window. Then clicking “Save” button.
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.
#7 Let’s see the last result:
You will see that all selected pictures have been resized to fit into cell size.
Leave a Reply
You must be logged in to post a comment.