Code advice for Match then populate userform

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,251
Office Version
  1. 2007
Platform
  1. Windows
Evening,
Can you assist please.

I have a worksheet which has values in the cells.
I would open my userform & type a value consisting of letters & numbers in TextBox 1
Pressing the command button the code would look for this value in column A and then populate the other Textboxes from info on worksheet.

Here is some info for you.

Worksheet caled KEYLESS
Userform called HondaKeylessForm
Command Button is called LoadInfo
On the worksheet column A has part numbers A3 & down the page.
The related info is as shown below.

TextBox 1 = Column A
TextBox 2 = Column C
TextBox 3 = Column E
TextBox 4 = Column G
TextBox 5 = Column I
TextBox 6 = Column K
TextBox 7 = Column M

So if i type 72147 ABC 123 in TextBox 1 the code should look at my worksheet for a match.
Once the match is found then put the value from that rows column into the Textbox.

Many thanks
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try this

VBA Code:
Private Sub CommandButton1_Click()
  If TextBox1.Value = "" Then
    MsgBox "Fill textbox1"
    TextBox1.SetFocus
    Exit Sub
  End If
  
  Dim f As Range, sh As Worksheet
  Set sh = Sheets("KEYLESS")
  Set f = sh.Range("A:A").Find(TextBox1.Value, , xlValues, xlWhole)
  If Not f Is Nothing Then
    TextBox2 = sh.Cells(f.Row, "C")
    TextBox3 = sh.Cells(f.Row, "E")
    TextBox4 = sh.Cells(f.Row, "G")
    TextBox5 = sh.Cells(f.Row, "I")
    TextBox6 = sh.Cells(f.Row, "K")
    TextBox7 = sh.Cells(f.Row, "M")
  Else
    MsgBox "Does not exists"
  End If
End Sub
 
Upvote 0
Evening @DanteAmor
Just a thought.

I might also add a photo.
Can I use a TextBox to display the photo in ?

If so TextBox8 would be where it will be shown BUT column O would be the path to the photo on the pc.

Photos are 640x480
Should a photo be a touch bigger can we apply a code to force it to 640x480 or does it not just show the way excess ?
 
Upvote 0
Can I use a TextBox to display the photo in ?

For that use the image control.
Note: In column O, you must have path, file name and file extension, example: C:\files\images\photo1.jpg

Try this

VBA Code:
Private Sub CommandButton1_Click()
  If TextBox1.Value = "" Then
    MsgBox "Fill textbox1"
    TextBox1.SetFocus
    Exit Sub
  End If
  
  Dim f As Range, sh As Worksheet, sFile As String
  Set sh = Sheets("KEYLESS")
  Set f = sh.Range("A:A").Find(TextBox1.Value, , xlValues, xlWhole)
  If Not f Is Nothing Then
    TextBox2 = sh.Cells(f.Row, "C")
    TextBox3 = sh.Cells(f.Row, "E")
    TextBox4 = sh.Cells(f.Row, "G")
    TextBox5 = sh.Cells(f.Row, "I")
    TextBox6 = sh.Cells(f.Row, "K")
    TextBox7 = sh.Cells(f.Row, "M")
    sFile = sh.Cells(f.Row, "O")
    If Dir(sFile) <> "" Then
      Image1.PictureSizeMode = fmPictureSizeModeStretch
      Image1.Picture = LoadPicture(sFile)
    End If
  Else
    MsgBox "Does not exists"
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,745
Messages
6,126,627
Members
449,323
Latest member
Smarti1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top