Put a loop for the code which insert pictures

Closed
hany - Jul 30, 2011 at 09:50 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Jul 30, 2011 at 04:50 PM
Hello,
Please i'm using Microsoft excel 2010 and need to do this code as a loop and if all the pics are inserted then the loop should break.




Sub Macro1()
    Range("B3") 'need to have the loop to B(i+18)
    ActiveSheet.Pictures.Insert("C:\Users\user\Pictures\Acceptance\1 (1).jpg").Select 'need to have loop for 1 (j+1).jpg
    Selection.ShapeRange.Height = 184.32
    Selecion.Cut
    ActiveSheet.Pictures.Paste.Select
End Sub
Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jul 30, 2011 at 04:50 PM
You can try some thing like this
Sub Macro1()
   Dim lStartAt         As Long
   Dim lEndAt           As Long
   Dim iCount           As Long
   Dim lCtr             As Long

   lStartAt = 4
   lEndAt = 22
      
   For lCtr = lStartAt To lEndAt
      iCount = iCount + 1
      Range ("B" & lCtr) 'need to have the loop to B(i+18)
      ActiveSheet.Pictures.Insert("C:\Users\user\Pictures\Acceptance\" & iCount & " (" & iCount & ").jpg").Select 'need to have loop for 1 (j+1).jpg
      Selection.ShapeRange.Height = 184.32
      Selecion.Cut
      ActiveSheet.Pictures.Paste.Select
   Next
End Sub
0