Match function returning type mismatch

mikejacobs

New Member
Joined
May 21, 2018
Messages
3
Hey guys, I just started using VBA and I keep getting type mismatch error from the code below


Code:
Dim testMock As Variant
    
    Dim wb As Workbook: Set wb = ThisWorkbook
        
    Dim Mock1 As Worksheet
    Set Mock1 = ThisWorkbook.Worksheets("Mock")
    
  
    
    Dim testnum As Variant
    
    testnum = 46361
    
    testMock = Mock1.Application.Match(testnum, "E2:E100", 0)
    
    
    
    MsgBox (testMock)

I am trying to search a worksheet called Mock in the column E for the number 46361 (I hard coded it that number for testing purposes) and return the row number (in this case, 2). I know for certain that the number exists in E2.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Have you tried...

Code:
testMock = Application.Match(testnum, Mock1.Range("E2:E100"), 0)
 
Last edited:
Upvote 0
I still get a type mismatch on MsgBox (testMock), is it an issue that testmock and testnum are declared as variants?
 
Upvote 0

Forum statistics

Threads
1,213,559
Messages
6,114,302
Members
448,564
Latest member
ED38

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