jimbofoxman
New Member
- Joined
- Feb 23, 2018
- Messages
- 13
Don't do much macro stuff in Excel. I have this piece of code I found somewhere a while back and have been using for some time. My question is, what code would I add to make it center the image in the cell vertically and horizontally?
Appreciate any help!
Code:
Sub piccy()
Dim sFile As Variant, r As Range, s As Range
sFile = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp), *.jpg;*.bmp", Title:="Browse to select a picture")
If sFile = False Then Exit Sub
On Error Resume Next
Set r = ActiveSheet.Range("B23")
'Set r = Application.InputBox("Click in the cell to hold the picture", Type:=8)
On Error GoTo 0
If r Is Nothing Then Exit Sub
If r.Count > 1 Then Exit Sub
ActiveSheet.Pictures.Insert (sFile)
With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
.LockAspectRatio = True
.Top = r.Top
.Left = r.Left
.Height = r.RowHeight * r.MergeArea.Rows.Count
End With
End Sub
Appreciate any help!