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.
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,336
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Have you tried...

Code:
testMock = Application.Match(testnum, Mock1.Range("E2:E100"), 0)
 
Last edited:

mikejacobs

New Member
Joined
May 21, 2018
Messages
3
I still get a type mismatch on MsgBox (testMock), is it an issue that testmock and testnum are declared as variants?
 

Watch MrExcel Video

Forum statistics

Threads
1,109,337
Messages
5,528,108
Members
409,802
Latest member
joeino

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top