Why am i getting a type mismatch 13 error

Sahil123

Well-known Member
Joined
Oct 31, 2011
Messages
673
Hi All,

I dont know why im getting a type mismatch 13 error
(TxtEmpID.Text is a textbox on my userform)

Thank You

Code:
Private Sub CmdAddRecord_Click()
Dim Found As Range
Set ws = Sheets("Sheet1")
LRow = ws.Range("A" & Rows.Count).End(xlUp).Row
With ws.Range("E6:E" & LRow)
 
   Set Found = .Find(What:=TxtEmpID.Text, After:=.Range("E6"), _
       LookIn:=xlValues, lookat:=xlWhole, SearchOrder:=xlNext, _
       MatchCase:=False, SearchFormat:=False)
    If Not Found Is Nothing Then
        Adr1 = Found.Address
    Else
       MsgBox "Name could not be found"
       Exit Sub
    End If
   
End With
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I dont know why im getting a type mismatch 13 error
(TxtEmpID.Text is a textbox on my userform)
Code:
Private Sub CmdAddRecord_Click()
Dim Found As Range
Set ws = Sheets("Sheet1")
LRow = ws.Range("A" & Rows.Count).End(xlUp).Row
With ws.Range("E6:E" & LRow)
 
   Set Found = .Find(What:=TxtEmpID.Text, After:=[B][COLOR=#a52a2a].Range("E6")[/COLOR][/B], _
       LookIn:=xlValues, lookat:=xlWhole, SearchOrder:=xlNext, _
       MatchCase:=False, SearchFormat:=False)
    If Not Found Is Nothing Then
        Adr1 = Found.Address
    Else
       MsgBox "Name could not be found"
       Exit Sub
    End If
   
End With
End Sub
The part I highlighted in red looks wrong to me. That leading dot makes the After argument this...

ws.Range("E6:E" & LRow).Range("E6")

which I am pretty sure points to the wrong cell. Try putting ws in front of that dot so the After argument points to E6 on the ws sheet or, since the first cell of the range is the default, just omit the entire After argument.
 
Upvote 0

Forum statistics

Threads
1,215,779
Messages
6,126,854
Members
449,345
Latest member
CharlieDP

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