TPortsmouth
New Member
- Joined
- Apr 6, 2017
- Messages
- 41
I've tried the below VBA code to auto resize image in Excel workbook. It fits with the cell.
However, can anyone help me how to make it valid on merged cell?
Thanks.
Code:
<code>Public Sub FitPicture()
On Error GoTo NOT_SHAPE
Dim PicWtoHRatio As Single
Dim CellWtoHRatio As Single
With Selection
PicWtoHRatio = .Width / .Height
End With
With Selection.TopLeftCell
CellWtoHRatio = .Width / .RowHeight
End With
Select Case PicWtoHRatio / CellWtoHRatio
Case Is > 1
With Selection
.Width = .TopLeftCell.Width
.Height = .Width / PicWtoHRatio
End With
Case Else
With Selection
.Height = .TopLeftCell.RowHeight
.Width = .Height * PicWtoHRatio
End With
End Select
With Selection
.Top = .TopLeftCell.Top
.Left = .TopLeftCell.Left
End With
Exit Sub
NOT_SHAPE:
MsgBox "Please select a picture first."
End Sub</code>
However, can anyone help me how to make it valid on merged cell?
Thanks.