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
    With Selection
        .ShapeRange.LockAspectRatio = msoFalse
        .ShapeRange.Height = 50#
        .ShapeRange.Width = 50#
        .ShapeRange.Rotation = 0#
        .Left = (Columns(picturePasteColumn).ColumnWidth - 50) / 2
        .Top = (Rows(pictureRow).RowHeight - 50) / 2
    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
        With Selection
            .ShapeRange.LockAspectRatio = msoFalse
            .ShapeRange.Height = 50#
            .ShapeRange.Width = 50#
            .ShapeRange.Rotation = 0#
            .Top = (Cells(pictureRow, picturePasteColumn).Top + _
                    Cells(pictureRow, picturePasteColumn).Height - .Height) / 2
            .Left = (Cells(pictureRow, picturePasteColumn).Left + _
                    Cells(pictureRow, picturePasteColumn).Width - .Width) / 2
        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
        With Selection
            .ShapeRange.LockAspectRatio = msoFalse
            .ShapeRange.Height = 50#
            .ShapeRange.Width = 50#
            .ShapeRange.Rotation = 0#
            .Top = Cells(pictureRow, picturePasteColumn).Top + _
                    (Cells(pictureRow, picturePasteColumn).Height - .Height) / 2
            .Left = Cells(pictureRow, picturePasteColumn).Left + _
                    (Cells(pictureRow, picturePasteColumn).Width - .Width) / 2
        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.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!