Forum Discussion
Ejman435
Nov 01, 2022Copper Contributor
VBA code for Training - No error but nothing appears after pressing search button
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 Intege...
- Nov 01, 2022
Sub 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").
OliverScheurich
Nov 01, 2022Gold Contributor
Sub 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").
Ejman435
Nov 04, 2022Copper Contributor
Dear Quadruple_Pawn,
Thank you so much for your help!!! It's solved 😄
Thank you so much for your help!!! It's solved 😄