Scale Image to Cell Dimensions - Partially Working VBA included!

sthrncaliguy

Board Regular
Joined
Jul 28, 2009
Messages
213
Ok all here is my macro so far..

Code:
  Sub FitImageToCell()
    Dim sPicture As String, pic As Picture, PicName As String
    PicName = ActiveSheet.Range("A9").Text
    Set pic = ActiveSheet.Pictures(PicName)
    With pic
      .Left = ActiveSheet.Cells(11, 22).Left
      .Top = ActiveSheet.Cells(11, 22).Top
      '.Height = ActiveSheet.Cells(11, 22).Height
      .Width = ActiveSheet.Cells(11, 22).Width
    End With
End Sub

It does place the image in the correct cell, and technical sizes it correctly, except the cell is a merged cell, but the pic is sized to the actual cell itself, not the merged cell.

Is there any way to modify the above code so that if my Cell V11 is a merged cell, that covers say 5 columns and 10 rows for example, the image would be sized appropriately?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try:
Code:
Sub FitImageToCell()
    Dim sPicture As String, pic As Picture, PicName As String, rng as range
    PicName = ActiveSheet.Range("A9").Text
    Set pic = ActiveSheet.Pictures(PicName)
    Set Rng = ActiveSheet.Cells(11, 22).MergeArea
    With pic
      .Left = Rng.Left
      .Top = Rng.Top
      '.Height = rng.Height
      .Width = Rng.Width
    End With
End Sub
 
Upvote 0
Try something like this...
Code:
.Width = ActiveSheet.Cells(11, 22)[COLOR="Red"].MergeArea[/COLOR].Width
 
Upvote 0
This is what I was exactly looking for..!! the MergeArea thing is awesome!!

Thanks!!!!
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,094
Latest member
bsb1122

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