Excel VBA 用户窗体运行时错误 - 在同一行上填充值查找引用

问题描述 投票:0回答:0

我在我的 vba 项目中遇到了另一个问题,当我在我的表单中插入一个值时,它会搜索该数字在第 1 列的位置,并将第 3 列和第 12 列同一行的值返回到表单。当我填写表格并按回车键时,它显示此错误:

“运行时错误‘-2147352571 (80020005)’: 无法设置值属性。类型不匹配。”

下面是代码:

Private Sub txtdevolução_AfterUpdate()

Dim id As String, rowcount As Integer, foundcell As Range

id = txtdevolução.Value

    rowcount = thisworkbook.Sheets("retornos pendentes").Cells(Rows.Count, 1).End(xlUp).Row

    With thisworkbook.Worksheets("retornos pendentes").Range("A1:A" & rowcount)
        Set foundcell = .Find(what:=id, LookIn:=xlValues, lookat:=xlWhole)

        If Not foundcell Is Nothing Then
            txtclienteopl.Value = .Cells(foundcell.Row, 3)
            txtmatricula2.Value = .Cells(foundcell.Row, 12)
         Else
            txtclienteopl.Value = ""
            txtmatricula2.Value = ""
        End If

    End With

End Sub

调试器停留的那一行是:"txtclienteopl.Value = .Cells(foundcell.Row, 3)"

NOTE: 另一个用户(我所在学院)在另一台电脑上出现错误,该文件在我们公司共享的网络磁盘上。

谢谢。

excel vba runtime-error userform
© www.soinside.com 2019 - 2024. All rights reserved.