Run-time error 13 Type Mismatch

reubanrao93

New Member
Joined
Dec 7, 2020
Messages
17
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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,406
Office Version
  1. 365
Platform
  1. Windows
What does N1 contain when you get the error?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,406
Office Version
  1. 365
Platform
  1. Windows
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?
 

reubanrao93

New Member
Joined
Dec 7, 2020
Messages
17
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,457
Office Version
  1. 365
Platform
  1. Windows
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.
 
Solution

reubanrao93

New Member
Joined
Dec 7, 2020
Messages
17
Office Version
  1. 365
Platform
  1. Windows
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
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,457
Office Version
  1. 365
Platform
  1. Windows
You're welcome. Glad we could help. Thanks for the follow-up. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,129,284
Messages
5,635,306
Members
416,852
Latest member
kanaikls

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
Top