I want to Search Data in my Excel Workbook
This code:
Private Sub search_Click()
Dim totRows As Long, i As Long
totRows = Worksheets("Sheet4").Range("A1").CurrentRegion.Rows.Count
If kodebus.Text = "" Then
MsgBox "Enter the code you wish to search!"
End If
For i = 2 To totRows
If Trim(Sheet4.Cells(i, 1)) <> Trim(kodebus.Text) And i = totRows Then
MsgBox "Code not found!"
End If
If Trim(Sheet4.Cells(i, 1)) = Trim(kodebus.Text) Then
kodebus.Text = Sheet4.Cells(i, 1)
namabus.Text = Sheet4.Cells(i, 2)
jurusanbus.Text = Sheet4.Cells(i, 3)
hargabus.Text = Sheet4.Cells(i, 4)
Exit For
End If
Next i
End Sub
Finally I get an Error, this message is "Subscript Out Of Range".
And get the position an Error in the code:
totRows = Worksheets("Sheet4").Range("A1").CurrentRegion.Rows.Count
Please help ve to solve it, thanks