Run-time error 13 Type Mismatch

reubanrao93

New Member
Joined
Dec 7, 2020
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Hey gurus,

I'm creating a macro sheet to run the following formula into column Q, however I keep running into Type mismatch 13 error over the InStr function. The raw data for Range N does not contain ",OPON" hence why the error occurs. Is there a way for me to modify this code to run even if the range don't have ",OPON" without stopping abruptly? Thank you

Sheets("OUTPUT").Range("Q:Q").Select
If InStr(1, (Range("N1").Value), ",OPON") > 0 Then
ActiveCell.Formula = "=LEFT(N1,FIND("",OPO"",N1)-1)"
Else: ActiveCell.Formula = "=LEFT(N1,4)"
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
What does N1 contain when you get the error?
 
Upvote 0
You will not get the error simply because N1 does not contain ",OPON" but you could get it if the cell contains an error.
So I will ask again what is in N1 when you get the error?
 
Upvote 0
You will not get the error simply because N1 does not contain ",OPON" but you could get it if the cell contains an error.
So I will ask again what is in N1 when you get the error?
N1 contains #VALUE!. Pasted as a text.
 
Upvote 0
N1 contains #VALUE!. Pasted as a text.
That will still be seen as an error. With that value pasted as text in N1, try these formulas in your worksheet
=ISTEXT(N1)
=ISERROR(N1)

In your code try
Rich (BB code):
If InStr(1, Range("N1").Text, ",OPON") > 0 Then

I am not sure that will give the result you want in the worksheet cell, but it should avoid the error that you have encountered.
 
Upvote 0
Solution
That will still be seen as an error. With that value pasted as text in N1, try these formulas in your worksheet
=ISTEXT(N1)
=ISERROR(N1)

In your code try
Rich (BB code):
If InStr(1, Range("N1").Text, ",OPON") > 0 Then

I am not sure that will give the result you want in the worksheet cell, but it should avoid the error that you have encountered.
Yeap changing to TEXT did it. Thank you Peter_SSs & Fluff
 
Upvote 0
You're welcome. Glad we could help. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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