Consulting

Results 1 to 3 of 3

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

  1. #1

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

    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!Book2.xlsm

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,874
    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
    Last edited by p45cal; 09-01-2018 at 03:01 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,874
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •