Run-time error 80020005 - Type mismatch on userform

aenemus

New Member
Joined
Mar 10, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I've run into another problem in my vba project, when i insert a value in my form, it searches where that number is on column 1 and returns the values from the same row on column 3 and 12 to the form. When i fill the form and press enter it shows this error:

"Run-time error '-2147352571 (80020005)':
Could not set value property. Type mismatch."

Bellow is the code:

VBA Code:
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

The line where the debuger stays is: txtclienteopl.Value = .Cells(foundcell.Row, 3)



Thanks.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this:
VBA Code:
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 =Range(foundcell.Row, 3)
            txtmatricula2.Value = Range(foundcell.Row, 12)
         Else
            txtclienteopl.Value = ""
            txtmatricula2.Value = ""
        End If

    End With

End Sub
 
Upvote 0
Thanks for the help,
but it gives the error time 1004 "method range of object_global failed"
 
Upvote 0
Hi,
untested but see if this update to your code will do what you want

VBA Code:
Private Sub txtdevolução_AfterUpdate()
    Dim id                  As String
    Dim foundcell           As Range
    Dim wsRetornosPendentes As Worksheet
   
     id = txtdevolução.Value
    If Len(id) = 0 Then Exit Sub
   
    Set wsRetornosPendentes = ThisWorkbook.Worksheets("retornos pendentes")
   
    Set foundcell = wsRetornosPendentes.Columns(1).Find(what:=id, LookIn:=xlValues, lookat:=xlWhole)
   
    If Not foundcell Is Nothing Then
        txtclienteopl.Value = foundcell.Offset(, 2)
        txtmatricula2.Value = foundcell.Offset(, 11)
    Else
        txtclienteopl.Value = ""
        txtmatricula2.Value = ""
    End If
   
End With

End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,806
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top