mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all

I have been having issues with my match function if there isnt a match found. I had initially had worksheetfunction.match but read that i need to change to application.match but im still getting a type mismatch error - where am i going wrong?
Code:
MatchHeaders = Application.Match(QuestionRange.Cells(rr, cc).Value, ws.Range(ws.Cells(2, 1), ws.Cells(2, Lcol)), 0)
                        
                        If IsError(MatchHeaders) Then
                            Outputsh.Cells(OutputLR, 12).Value = 1
Outputsh.Cells(OutputLR, 15).Value = "Question not found"
                        Elseif not isnumber(ws.Cells(i, MatchHeaders))
                           Outputsh.Cells(OutputLR, 12).Value = 1
Outputsh.Cells(OutputLR, 15).Value = "Not a valid entry"
else
  Outputsh.Cells(OutputLR, 12).Value = ws.Cells(i, MatchHeaders)                      
End If
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How did you declare the variable MatchHeaders? If you declare it as a Long or an Integer, then you will get a mismatch error if no match is found because Application.Match will return an error, not a long or integer. Declare it as a Variant or add an error trap.
 
Upvote 0
Hiya

i declared it as long as normally that cell should have a number so im guessing trapping the error would be alternative which i thought i tried with iserror function

if there isnt a match then display a 1 in the cell and display “question not found” in column 15
if there is a match but the cell doesn’t contain a number (blank, text, rrror) etc then display 1 and in column 15 display “Not a valid entry”
else display the number as normal

this is what i tried doing with the example i showed with the match function

thank you once again
 
Upvote 0
isError doesn't trap the error. Easier to declare the variable as a Variant.
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,198
Latest member
MhammadishaqKhan

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