I have a code that works great for a cell that isn't merged. The idea is to size and center the picture in whatever cell I select. (bottom image)
However, I want this to work when I've merged several columns too. The code is still just recognizing column B for inserting the picture and it looks like this:
But I'd like it to look like this:
However, I want this to work when I've merged several columns too. The code is still just recognizing column B for inserting the picture and it looks like this:
But I'd like it to look like this:
VBA Code:
Sub InsertPic()
'Add picture...centered...scaled
Dim fNameAndPath As Variant
Dim rng As Range
Dim img As Picture
fNameAndPath = Application.GetOpenFilename( _
FileFilter:="Image Files (*.gif;*.jpg;*.png), *.gif;*.jpg;*.png", _
Title:="Select an Image", _
ButtonText:="Select")
If fNameAndPath = False Then Exit Sub
Set rng = ActiveCell
Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
With img
If .Width > .Height Then
.Width = rng.Width * 0.7
Else
.Height = rng.Height * 0.7
End If
.Left = rng.Left + (rng.Width - .Width) / 2
.Top = rng.Top + (rng.Height - .Height) / 2
.Placement = 1
.PrintObject = True
End With
End Sub