Fish fingers
New Member
- Joined
- Feb 2, 2020
- Messages
- 5
- Office Version
- 2016
- Platform
- Windows
I want to extract data from sheet to form and I tried a code that I got from a certain video on YouTube. I wrote mine based on the tutorial and this is what I came up with
```
Private Sub ComboBox1_DropButtonClick()
Dim i As Long, LastRow As Long
LastRow = Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
If Me.ComboBox1.ListCount = 0 Then
For i = 2 To LastRow
Me.ComboBox1.AddItem Sheets("sheet1").Cells(i, "A").Value
Next i
End If
End Sub
Private Sub ComboBox1_Change()
Dim i As Long, LastRow As Long
LastRow = Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
If Me.ComboBox1.ListCount = 0 Then
For i = 2 To LastRow
If Sheets("sheet1").Cells(i, "A").Value = Val(Me.ComboBox1) Then
Me.TextBox1 = Sheets("sheet1").Cells(i, "B").Value
Me.TextBox2 = Sheets("sheet1").Cells(i, "C").Value
Me.TextBox3 = Sheets("sheet1").Cells(i, "D").Value
Me.TextBox4 = Sheets("sheet1").Cells(i, "E").Value
Me.TextBox5 = Sheets("sheet1").Cells(i, "F").Value
Me.TextBox6 = Sheets("sheet1").Cells(i, "G").Value
Me.TextBox7 = Sheets("sheet1").Cells(i, "H").Value
End If
Next
End If
End Sub
Private Sub CommandButton1_Click()
Unload UserForm5
End Sub
Private Sub UserForm_Click()
End Sub
```
The code is running but when I place the dropbutton click on the combobox, am not getting the display of data from the sheet. When I select weights for example. It should show the figures on the corresponding label as shown in the pictures. What's the problem? or maybe someone should just write me a code that works for what I want.
Thanks in advance
```
Private Sub ComboBox1_DropButtonClick()
Dim i As Long, LastRow As Long
LastRow = Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
If Me.ComboBox1.ListCount = 0 Then
For i = 2 To LastRow
Me.ComboBox1.AddItem Sheets("sheet1").Cells(i, "A").Value
Next i
End If
End Sub
Private Sub ComboBox1_Change()
Dim i As Long, LastRow As Long
LastRow = Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
If Me.ComboBox1.ListCount = 0 Then
For i = 2 To LastRow
If Sheets("sheet1").Cells(i, "A").Value = Val(Me.ComboBox1) Then
Me.TextBox1 = Sheets("sheet1").Cells(i, "B").Value
Me.TextBox2 = Sheets("sheet1").Cells(i, "C").Value
Me.TextBox3 = Sheets("sheet1").Cells(i, "D").Value
Me.TextBox4 = Sheets("sheet1").Cells(i, "E").Value
Me.TextBox5 = Sheets("sheet1").Cells(i, "F").Value
Me.TextBox6 = Sheets("sheet1").Cells(i, "G").Value
Me.TextBox7 = Sheets("sheet1").Cells(i, "H").Value
End If
Next
End If
End Sub
Private Sub CommandButton1_Click()
Unload UserForm5
End Sub
Private Sub UserForm_Click()
End Sub
```
The code is running but when I place the dropbutton click on the combobox, am not getting the display of data from the sheet. When I select weights for example. It should show the figures on the corresponding label as shown in the pictures. What's the problem? or maybe someone should just write me a code that works for what I want.
Thanks in advance