Re-sizing picture to fit cell

magik_johnson

New Member
Joined
Nov 14, 2018
Messages
2
Hi all,
Apologies if i have posted this in the wrong place!
Im trying to make it simple for users of a workbook to insert an image. So far I have inserted an activeX image control and used this code (found online) so they can select an image to add to the cell-

Private Sub Image1_Click()
With Application.Dialogs(xlDialogInsertPicture)
If .Show = True Then
With Selection.ShapeRange
.Width = Image1.Width
.Height = Image1.Height
.Top = Image1.Top
.Left = Image1.Left
End With
End If
End With

End Sub

My issue is that I need the inserted image to automatically re-size to the the dimensions of the cell it is inserted into. I've tried a few things but my knowledge of VBA is pretty much non-existent!
Any help would be really appreciated!
Thanks
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Is this what you want

Code:
Private Sub Image1_Click()
    With Application.Dialogs(xlDialogInsertPicture)
        If .Show = True Then
            With Selection.ShapeRange
               [COLOR=#ff0000][I] .LockAspectRatio = msoFalse[/I][/COLOR]
                .Width = Image1.Width
                .Height = Image1.Height
                .Top = Image1.Top
                .Left = Image1.Left
            End With
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top