PDA

View Full Version : Auto-Size Pasted Picture/Snippet to Fit Cell Height and Width



anonymo123
08-31-2018, 11:13 PM
I’m trying to create a set of flashcards in Excel that utilizes a named range lookup for the active flashcard (one example here: https://youtu.be/rTyZmSHDLBA), which works fine.

If the image is larger than the referenced cell being looked up, then the named range formula doesn’t work correctly. So, I’m trying to figure out a way to either resize the cells the image touches or resize the image to fit the cell. Either solution would be sufficient.

Not sure if this is helpful, but I added a sample file.

Thanks for your help!22807

p45cal
09-01-2018, 02:40 AM
This snippet will act in relation to the cell that the selected image's top left corner is in:
1. To reposition the image to the very top left of the cell
2. To adjust the cell size to fit the image. The column width will only increase if necessary (it won't reduce (this is because I've assumed all your pictures are in the same column)):

Sub blah()
With Selection.TopLeftCell
Selection.Top = .Top
Selection.Left = .Left
.RowHeight = Selection.Height
For i = 1 To 3
.ColumnWidth = Application.Max(.ColumnWidth, Selection.Width * .ColumnWidth / .Width)
Next i
End With
End Sub

p45cal
09-01-2018, 11:23 AM
Grrr. Cross posted without telling us, wholesale:
https://www.mrexcel.com/forum/excel-questions/1069162-auto-size-pasted-picture-snippet-fit-cell-height-width.html#post5135111
https://chandoo.org/forum/threads/auto-size-pasted-picture-snippet-to-fit-cell-height-and-width.39645/
https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/1207787-auto-size-pasted-picture-snippet-to-fit-cell-height-and-width