How to populate image control in Excel user form with data from worksheet using VBA

How to transfer data from an Excel worksheet to an Excel form including pictures to an image control.

  1. Create an Excel file with names. You can also add other details like address, phone numbers, etc.
  2. Now place all the images and the Excel file in the same folder
  3. In the Excel worksheet with the data place a command button which on click will open a user form to which you wish to transfer the data including images to an image control

Private Sub CommandButton1_Click()

Adding a picture relevant to the name

When you click on the command button ‘show form’ a user-form appears. The detailed code of each item on the user form is shown below:
Private Sub CommandButton1_Click()
Dim NameFound As Range
Dim fPath As String
Row = 2
For Row = Row To 11
With Cells(Row, 1)
TextBox1.Text = Cells(Row, 1)
Set NameFound = .Find(TextBox1.Value)
If NameFound Is Nothing Then
Image1.Picture = LoadPicture(fPath & “nopic.gif”)
With NameFound
fPath = ThisWorkbook.Path & “\”
Image1.Picture = LoadPicture(fPath & “\” & TextBox1.Value & “.jpg”)
MsgBox (“Picture of “) & TextBox1.Value
End With
End If
End With
End Sub
Private Sub CommandButton3_Click()
End Sub
Keep the Excel file and the image file in the same folder.
Name the images so that the names for the images and the names entered in the Excel worksheet match.

Watch the video:

Further reading:
Load Worksheet Picture Into UserForm Image Control

2 thoughts on “How to populate image control in Excel user form with data from worksheet using VBA

  1. Pingback: Best Training on Advanced Excel and VBA

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.