Type Mismatch trying to find cell value

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
I'm using this to try and identify which row a cell values appears on another sheet;

Code:
Dim YourVariable As VariantDim rowCount As Integer
Set YourVariable = Sheet21.Range("B2").Value
With ActiveSheet.Range("A:A")
    Set uRng = .Find(YourVariable, , xlValues, xlWhole, , MatchCase:=False, searchformat:=False)
    If Not uRng Is Nothing Then
        uRng.Activate
        rowCount = ActiveCell.Row
    End If
End With

I am getting a Type Mismatch Error 13 on this line if anyone knows why;

Code:
Set YourVariable = Sheet21.Range("B2").Value

For info, the cell B21 contains a lot of text and some numbers.
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try:
Code:
YourVariable = Sheet21.Range("B2").Value
 
Upvote 0
Hi

You are using Set YourVariable...

Set is for Objects but you are after the Value property. Either lose the Set or replace with Let.
 
Upvote 0
Remove the:- .Value
Code:
set YourVariable = Sheet21.Range("B2").Value
 
Last edited:
Upvote 0
Guys,

Thanks for your suggestions - I have amended my code as follows;

Code:
Dim YourVariable As VariantDim rowCount As Integer
YourVariable = Sheet21.Range("B21").Value
 
With Sheet28.Range("A2:A267")
Set uRng = .Find(YourVariable, , xlValues, xlWhole, , MatchCase:=False, searchformat:=False)
If Not uRng Is Nothing Then
uRng.Activate
rowCount = ActiveCell.Row


MsgBox rowCount
End If
End With

However I am still getting a Type Mismatch.......sorry if I have missed something obvious?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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