I am trying to select pictures which are in random cells in column "K" and place them in row 1, starting at column "K". I am able to copy each picture with the below code.
I am trying to find the first cell starting at row "K" which doesn't have a shape in it. I am looping through all of the pictures .TopLeftCell.Address
and comparing it with the current cells .Address
to copy.
I can't figure out how to begin another loop to check if the cells do not have a shape in them, as I am already using the For Each picS In ActiveSheet.Shapes
loop and can't loop it again inside its own loop.
Sub findPics()
Dim picRng As Range
Dim picS As Shape
Dim picAdd As Range
Dim lRow As Long
For lRow = 2 To 30
For Each picS In ActiveSheet.Shapes
Set picAdd = Range(picS.TopLeftCell.Address)
If ActiveSheet.Range("K" & lRow).Address = picAdd.Address Then
Debug.Print "Picture " & picS.ID; " in cell" & ActiveSheet.Range("K" & lRow).Address
Range(picAdd.Address).CopyPicture
'Need to find first cell of row 1 without image in it starting at column "K"
Else
Debug.Print "Picture " & picS.ID; " isn't in" & ActiveSheet.Range("K" & lRow).Address
End If
Next picS
Next lRow
End Sub