Automatically resize a picture to a cell

D

Dave Peterson

I use this to add a picture. Maybe you can pick out the pieces you need:


Option Explicit
Sub testme01()

Dim myPict As Picture
Dim myPictName As String

myPictName = "C:\test.jpg"

With ActiveSheet
With .Range("a1:b9")
Set myPict = .Parent.Pictures.Insert(Filename:=myPictName)
myPict.Top = .Top
myPict.Left = .Left
myPict.Width = .Width
myPict.Height = .Height
myPict.Name = "Pict_" & .Cells(1).Address(0, 0)
End With
End With
End Sub

I'm not sure if you want to fix the .width or the .height, though.




Manually, you could adjust its size/position by holding down the Alt key and
using the grab handles. The picture will snap-to the edges of the cells.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top