'vba excel userform
1.I'm trying to write a VBA script to create a user form in Excel to search in a database when I write the search button code it gave me an error in the 5th line ( If Trim(Data.Cells(i, 1)) <> Trim(txtsearch.Text) And i = isearch Then )
Appreciate if anyone have a solution for that.
2.Code :
Private Sub Comsear_Click()
Dim isearch As Long, i As Long
isearch = Worksheets("Data").Range("A1").CurrentRegion.Rows.Count
For i = 10 To isearch
If Trim(Data.Cells(i, 1)) <> Trim(txtsearch.Text) And i = isearch Then
MsgBox ("Invalid data")
txtsearch.Text = ""
txtsearch.SetFocus
End If
If Trim(Data.Cells(i, 1)) = Trim(txtsearch.Text) Then
Texgl.Text = Data.Cells(i, 1)
Texitem.Text = Data.Cells(i, 2)
Texid.Text = Data.Cells(i, 3)
Texgender.Text = Data.Cells(i, 4)
Texb5.Text = Data.Cells(i, 5)
Texb4.Text = Data.Cells(i, 6)
Texpc.Text = Data.Cells(i, 7)
Texpcid.Text = Data.Cells(i, 8)
Exit For
End If
Next i
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
