Hi Mukesh,
The i is an index so that you could run right down the column - but the spacing would have to be regular.
Here's some code to Name "N" Resize and Move a picture in Range "R" to Range "S":
Sub PositionPic() 'Use this code to invoke the actual procedure
Call NameandMovePic("Logo",Range("B3"), Range("D3"))
End Sub
Sub NameandMovePic(N As String,R As Range, S As Range)
Dim pic As Object, ws As Worksheet
Set ws = ActiveSheet
For Each pic In ws.Shapes
If Abs(pic.Left - R.Left) < 10 Then
pic.Name = N: pic.Left = S.Left: pic.Top = S.Top
Exit Sub: End If: Next
End Sub
This seemed to work pretty well a tolerance of 22 was too much but needed to be 21 to catch President Obama:
Private Sub CommandButton1_Click()
Dim pic As Object, N As String, ws As Worksheet, R As Range
Set ws = ActiveSheet
For Each pic In ws.Shapes
If Abs(pic.Left - Range("D1").Left) < 21 Then
If pic.Type = msoPicture Then
N = pic.Name
pic.LockAspectRatio = msoFalse
pic.Width = Application.CentimetersToPoints(3)
pic.Height = Application.CentimetersToPoints(4)
End If: End If
For Each R In Range("D1:D" & Range("B" & Rows.Count).End(xlUp).row)
If Abs(pic.Top - R.Top) < 21 Then
pic.Left = R.Left: pic.Top = R.Top: R.RowHeight = pic.Height
Exit For: End If: Next
Next pic
End Sub
Bookmarks