Run-time error '13': Type mismatch

pells

Active Member
Joined
Dec 5, 2008
Messages
361
I am trying to the the following code but I am getting this error, run-time error '13': Type mismatch:

If ActiveSheet.Range("G11:G88") > 0 Then
MsgBox "No code entered!", vbExclamation, "Error"
Exit Sub
End If

Am I using the correct syntax and does anyone know how to resolve my error so that it works?

Many thanks.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
What is it about G11:G88 that must be greater than 0?
 
Upvote 0
I think you're trying to evaluate an object (range of cells i.e. G11:G88) against a numerical rule - the two are not comparable, hence the type mismatch error.

What are you trying to achieve, that if any value in that range is greater than 0 to provide the error message? Or if all values in that range is greater than 0 to provide the error message?

If you're testing for a postive integer, are you expecting all the values (or any?) in that range to be non-positive?
 
Upvote 0
I think you're trying to evaluate an object (range of cells i.e. G11:G88) against a numerical rule - the two are not comparable, hence the type mismatch error.

What are you trying to achieve, that if any value in that range is greater than 0 to provide the error message? Or if all values in that range is greater than 0 to provide the error message?

If you're testing for a postive integer, are you expecting all the values (or any?) in that range to be non-positive?
Hi,

I am looking for if any value in that range is greater than 0 to provide the error message.

Thanks.
 
Last edited:
Upvote 0
You've given 2 different answers to the question of what you want...

1.
If something is NOT entered in any cell from G11 to G88 then produce an error message.

2.
I am looking for if any value in that range is greater than 0 to provide the error message.


Those are 2 very different objectives, which is it?

My previous post answers version 1...

Perhaps this answers version 2 of your request..

If Application.Max(ActiveSheet.Range("G11:G88")) > 0 Then
 
Upvote 0
Jonmo suggests a better alternative, but this checks for positive numbers only:
Code:
If Application.Max(Range("G11:G88")) > 0 Then
        MsgBox ("No code entered!", vbExclamation, "Error")
        Exit Sub
End If
To check for any cell being blank in that range:
Code:
If Application.CountBlank(Range("G11:G88")) > 0 Then
MsgBox ("No code entered!", vbExclamation, "Error")
        Exit Sub
End If
And if both are combined:
Code:
If Application.CountBlank(Range("G11:G88")) > 0 OR _
   Application.Max(Range("G11:G88")) > 0 Then
MsgBox ("No code entered!", vbExclamation, "Error")
        Exit Sub
End If
 
Last edited:
Upvote 0
Apologies all if I have made this confusing and many thanks for all your replies.

What I am after is the following:

If there is something entered in cell range G11 to G88 AND if there isn't something in cell range H11 to H88 then produce an error

I hope this makes sense and hope you can assist me - many thanks.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,681
Members
452,937
Latest member
Bhg1984

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