VBA Excel用户形式

发布于 2025-01-27 08:38:01 字数 1003 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文