Insert an image into a cell

W

Wayne.Miller

I would like to insert an image into a cell. Is this possible?

When I paste an image into Excel, it floats on top of the cells. I
would like to insert it into a cell. It would be even better if it
would automatically scale itself into the size of the cell, i.e., if
the cell size changes the image's size would also change automatically.
Am I asking for too much?
 
J

JE McGimpsey

I would like to insert an image into a cell. Is this possible?

When I paste an image into Excel, it floats on top of the cells. I
would like to insert it into a cell. It would be even better if it
would automatically scale itself into the size of the cell, i.e., if
the cell size changes the image's size would also change automatically.
Am I asking for too much?

Cells can contain values or formulas. Pictures (except for watermarks,
which live "below" the sheet) live in the Drawing layer above the cells.
You can use a macro to scale and set the picture to expand/contract to
fit a cell. This macro scales the last picture inserted to the cell that
contains its top left corner, keeping the original's proportions, then
sets the picture to change shape as the cell does:

Public Sub ScalePic()
Dim rCell As Range
Dim dFactor As Double
With ActiveSheet.Pictures
With .Item(.Count)
Set rCell = .TopLeftCell
.Top = rCell.Top
.Left = rCell.Left
dFactor = rCell.Width / .Width
.Width = rCell.Width
.Height = .Height * dFactor
If .Height > rCell.Height Then
dFactor = rCell.Height / .Height
.Height = rCell.Height
.Width = .Width * dFactor
End If
.Placement = xlMoveAndSize
End With
End With
End Sub

If you're not familiar with macros, see David McRitchie's "Getting
Started with Macros":

http://www.mvps.org/dmcritchie/excel/getstarted.htm
 

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