Inserting Picture & Autofit Can Work on Single & Merged Cell

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
1,762
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
hi expert..
i found code to Inserting picture in a cell (autofit), but this code work in single cell..
i want this code working on single cell and merged cell
here this code
(how to modify it)
VBA Code:
Sub InsertPicture()
Dim sPicture As String, pic As Picture

sPicture = Application.GetOpenFilename _
("Pictures (*.gif; *.jpg; *.bmp; *.tif), *.gif; *.jpg; *.bmp; *.tif", _
, "Select Picture to Import")

If sPicture = "False" Then Exit Sub

Set pic = ActiveSheet.Pictures.Insert(sPicture)
With pic
.ShapeRange.LockAspectRatio = msoFalse
.Height = ActiveCell.Height
.Width = ActiveCell.Width
.Top = ActiveCell.Top
.Left = ActiveCell.Left
.Placement = xlMoveAndSize
End With

Set pic = Nothing

End Sub

anyone help me, thank very much
.sst
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,359
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi muhammad. This is untested, but give it a try:

VBA Code:
With Pic
.ShapeRange.LockAspectRatio = msoFalse
.Height = ActiveCell.MergeArea.Height
.Width = ActiveCell.MergeArea.Width
.Top = ActiveCell.MergeArea.Top
.Left = ActiveCell.MergeArea.Left
.Placement = xlMoveAndSize
End With
 

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
1,762
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Hi muhammad. This is untested, but give it a try:

VBA Code:
With Pic
.ShapeRange.LockAspectRatio = msoFalse
.Height = ActiveCell.MergeArea.Height
.Width = ActiveCell.MergeArea.Width
.Top = ActiveCell.MergeArea.Top
.Left = ActiveCell.MergeArea.Left
.Placement = xlMoveAndSize
End With

hi JoeMo,,,,
wowwwww...very fast like F1,...
Worked well. Perfecto...
thank you so much!!!!
 

Watch MrExcel Video

Forum statistics

Threads
1,118,773
Messages
5,574,149
Members
412,574
Latest member
shadowfighter666
Top