• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Auto-Size Pasted Picture/Snippet to Fit Cell Height and Width

anonymo123

New Member
I’m trying to create a set of flashcards in Excel that utilizes a named range lookup for the active flashcard (one example here:
), 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!
 

Attachments

  • Book2.xlsm
    13.5 KB · Views: 4
Does this help?
Code:
Sub ResizePictureCells()
For Each Picture In ActiveSheet.DrawingObjects
PictureTop = Picture.Top
PictureLeft = Picture.Left
PictureHeight = Picture.Height
PictureWidth = Picture.Width
For N = 2 To 256
If Columns(N).Left > PictureLeft Then
PictureColumn = N - 1
Exit For
End If
Next N
For N = 2 To 65536
If Rows(N).Top > PictureTop Then
PictureRow = N - 1
Exit For
End If
Next N
Rows(PictureRow).RowHeight = PictureHeight
Columns(PictureColumn).ColumnWidth = PictureWidth * (54.29 / 288)
Picture.Top = Cells(PictureRow, PictureColumn).Top
Picture.Left = Cells(PictureRow, PictureColumn).Left
Next Picture
End Sub
 
Back
Top