Documente Academic
Documente Profesional
Documente Cultură
Home
Home
Products
Documents
Download
Excel
Purchase
Support
Languages
Hint
How to be
more efficient
and save time when using Excel?
Firefox, Chrome, Internet Explore 10!
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.
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.
1 Public Sub FitPic()
2 On Error GoTo NOT_SHAPE
3 Dim PicWtoHRatio As Single
4 Dim CellWtoHRatio As Single
5 With Selection
6 PicWtoHRatio = .Width / .Height
7 End With
8 With Selection.TopLeftCell
9 CellWtoHRatio = .Width / .RowHeight
10 End With
11 Select Case PicWtoHRatio / CellWtoHRatio
12 Case Is > 1
13 With Selection
14 .Width = .TopLeftCell.Width
15 .Height = .Width / PicWtoHRatio
16 End With
17 Case Else
18 With Selection
19 .Height = .TopLeftCell.RowHeight
20 .Width = .Height * PicWtoHRatio
21 End With
22 End Select
23 With Selection
24 .Top = .TopLeftCell.Top
25 .Left = .TopLeftCell.Left
26 End With
27 Exit Sub
28 NOT_SHAPE:
29 MsgBox "Select a picture before running this macro."
30 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:
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.
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 120 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:
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:
Step 3: Check Matching cell size option. Then click Ok > Import to close dialogs. See screenshot:
Now you can see the pictures are inserted to fit the cells.
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?
Comments
0 # Jim Abramczyk 2014-03-23 19:55
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!
Reply | Reply with quote | Quote
0 # lucy 2014-05-29 16:39
Instructions for Excel
Reply | Reply with quote | Quote
0 # Monika 2014-11-03 15:35
Thank you this was perfect!!
Reply | Reply with quote | Quote
0 # Marcelo 2015-07-06 13:38
Works!!
But i have one question, i want to fit a img in a range of cells merged, how can i do it?
Reply | Reply with quote | Quote
Refresh comments list
Add comment
Name (required)
Refresh
Send
Home
Documents
Support
Privacy Policy
Contact Us
Copyright 2009 - 2015 ExtendOffice.com | All Rights Reserved.
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.