i am very new to VBA program i am not sure how to perform my requirement
Here ,my requirement is In my Excel sheet having 3 columns. Column names(S.no,S,E). I want to insert the Images in to S and E columns based on the matching S.no and Image name ,All my images are in another folder .
sample input format
S.no S E
1
2
99
Images names in the folder
c:\iamges\E_001.jpg
c:\images\E_002.jpg
c:\images\S_002.jpg
c:\images\E_099.jpg
Required output format in the cells
S.no S E
1 E_001.jpg
2 S_002.jpg E_002.jpg
99 E_099.jpg
Here S.no 1 is matching the E_001.jpg image
S.no 2 is matching the S_002.jpg and E_002.jpg images in the folder
In the similar way matching all the images and filled in to cells.
I am trying the following code
strFolder = "C:\\images" 'change the path accordingly
If Right(strFolder, 1) <> "\" Then
strFolder = strFolder & "\"
End If
Set rngCell = Range("c5") 'starting cell
strFileName = Dir(strFolder & "E*.jpg", vbNormal) 'filter for .jpg files
Do While Len(strFileName) > 0
Set objPic = ActiveSheet.Pictures.Insert(strFolder & strFileName)
With objPic
.ShapeRange.LockAspectRatio = False
.Left = rngCell.Left
.Top = rngCell.Top
.Height = rngCell.Height
.Width = rngCell.Width
.Placement = xlMoveAndSize
End With
Set rngCell = rngCell.Offset(1, 0)
strFileName = Dir
Loop
the above code fill all the images in to cell with out matching the filename and S.no