Center picture in cells -VBA

  • Hello !


    i need help modifying the code below. the code only lacks the centering of the photo in the cells, the rest works smoothly. The width and height of the cell is set earlier.
    Thx for help!

  • Try this

    Code
    1. With Selection
    2. .ShapeRange.LockAspectRatio = msoFalse
    3. .ShapeRange.Height = 50#
    4. .ShapeRange.Width = 50#
    5. .ShapeRange.Rotation = 0#
    6. .Left = (Columns(picturePasteColumn).ColumnWidth - 50) / 2
    7. .Top = (Rows(pictureRow).RowHeight - 50) / 2
    8. End With

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • How did you modify your code to include my suggestion?

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Please look below

  • Try this instead

    Code
    1. With Selection
    2. .ShapeRange.LockAspectRatio = msoFalse
    3. .ShapeRange.Height = 50#
    4. .ShapeRange.Width = 50#
    5. .ShapeRange.Rotation = 0#
    6. .Top = (Cells(pictureRow, picturePasteColumn).Top + _
    7. Cells(pictureRow, picturePasteColumn).Height - .Height) / 2
    8. .Left = (Cells(pictureRow, picturePasteColumn).Left + _
    9. Cells(pictureRow, picturePasteColumn).Width - .Width) / 2
    10. End With

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Sorry, brackets were wrong, try

    Code
    1. With Selection
    2. .ShapeRange.LockAspectRatio = msoFalse
    3. .ShapeRange.Height = 50#
    4. .ShapeRange.Width = 50#
    5. .ShapeRange.Rotation = 0#
    6. .Top = Cells(pictureRow, picturePasteColumn).Top + _
    7. (Cells(pictureRow, picturePasteColumn).Height - .Height) / 2
    8. .Left = Cells(pictureRow, picturePasteColumn).Left + _
    9. (Cells(pictureRow, picturePasteColumn).Width - .Width) / 2
    10. End With

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • You're welcome. Thanks for the Like

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.