VBA Excel用户形式
1.我正在尝试编写一个VBA脚本以在Excel中创建一个用户表单以在我编写搜索按钮代码时在数据库中搜索,这给了我第五行中的错误(如果Trim(data.cells(i,1,1)) )<> txtsearch.text)和i = iSearch)
如果有人对此有解决方案。
2.编码:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论