Nov 01 2022 03:52 AM - edited Nov 01 2022 03:56 AM
Hello,
I am learning how to code to work around training management better, however I am stuck on the following code:
Sub CommandButton1_Click()
Dim cust_id As String
Dim lastrow As Integer
Dim i As Integer
cust_id = Trim(TextBox1.Text)
lastrow = Worksheet("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If TextBox1.Text = Worksheet("Sheet1").Cells(i, 1).Value Then
TextBox2.Text = Worksheet("Sheet1").Cells(i, 2).Value
TextBox3.Text = Worksheet("Sheet1").Cells(i, 3).Value
TextBox4.Text = Worksheet("Sheet1").Cells(i, 4).Value
End If
Next
End Sub
After typing and pressing the search button for an ID e.g, 310, the other results (First Name, Last Name, etc) are not appearing.
Can you please help?
Thank you.
Ejman
Nov 01 2022 05:38 AM
SolutionSub CommandButton1_Click()
Dim cust_id As String
Dim lastrow As Integer
Dim i As Integer
cust_id = Trim(TextBox1.Text)
lastrow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If TextBox1.Text = Worksheets("Sheet1").Cells(i, 1).Value Then
TextBox2.Text = Worksheets("Sheet1").Cells(i, 2).Value
TextBox3.Text = Worksheets("Sheet1").Cells(i, 3).Value
TextBox4.Text = Worksheets("Sheet1").Cells(i, 4).Value
End If
Next
End Sub
It works in my sheet after changing Worksheet("Sheet1") to Worksheets("Sheet1").
Nov 03 2022 08:33 PM