Forum Discussion

Ejman435's avatar
Ejman435
Copper Contributor
Nov 01, 2022

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...
  • OliverScheurich's avatar
    Nov 01, 2022

    Ejman435 

    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").

Resources