Solved

VBA Run-Time Error 13

Posted on 2011-02-11
10
325 Views
Last Modified: 2012-06-21
Hi all,

When I input the following code, I get runtime error 13, type mismatch upon running it. This only occurs when the referenced cells (F8,H8,G8,I8) are blank. If I do input numbers into those cells, the code runs fine. Any ideas why this may be? Thanks.

Private Sub worksheet_deactivate()

If Evaluate("IF(AND(AND(OR(((F8-I8)/I8>0.2),((F8-I8)/I8<-0.2)),NOT(ISBLANK(I8)),NOT(ISBLANK(F8))),AND(NOT(ISBLANK(F8)),NOT(ISBLANK(G8)),NOT(ISBLANK(H8)),NOT(SUM(G8+H8)=F8))),TRUE,FALSE)") Then
MsgBox "Test", vbOKCancel

End If
End Sub
0
Comment
Question by:shoaibs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34871660
Try this

Private Sub worksheet_deactivate()
    On Error Resume Next
    If Evaluate("IF(AND(AND(OR(((F8-I8)/I8>0.2),((F8-I8)/I8<-0.2)),NOT(ISBLANK(I8)),NOT(ISBLANK(F8))),AND(NOT(ISBLANK(F8)),NOT(ISBLANK(G8)),NOT(ISBLANK(H8)),NOT(SUM(G8+H8)=F8))),TRUE,FALSE)") Then
    MsgBox "Test", vbOKCancel
    
    End If
    On Error GoTo 0
End Sub

Open in new window


Sid
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 34871715
Or assign it to a Variant and use IsError:
Private Sub worksheet_deactivate()
Dim varReturn
varReturn = Evaluate("IF(AND(AND(OR(((F8-I8)/I8>0.2),((F8-I8)/I8<-0.2)),NOT(ISBLANK(I8)),NOT(ISBLANK(F8))),AND(NOT(ISBLANK(F8)),NOT(ISBLANK(G8)),NOT(ISBLANK(H8)),NOT(SUM(G8+H8)=F8))),TRUE,FALSE)") 
If Not IsError(varreturn) Then
  If varReturn Then MsgBox "Test", vbOKCancel
End If
End Sub

Open in new window

0
 
LVL 6

Expert Comment

by:Eric Zwiekhorst
ID: 34871747
Dear shoaibs,


the problem is caused because the formula has this F8-I8)/I8>0.2),((F8-I8)/I8<-0.2)),
and if the cells or blank excel can not calulate..

You have to test before if the cells are empty and if not you can calculate the rest..

Kind regards

Eric
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:shoaibs
ID: 34871825
Hi Sid,

Thanks for the response. I'm using the popup message as a validation of sorts. When I use your code, the textbox pops up even if the cells are blank, I need the msgbox to only appear if the evaluate statement is true. Any ideas on how to accomplish this?

Thanks.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34871985
Did you try Rory's code?

Sid
0
 

Author Comment

by:shoaibs
ID: 34872030
Rory's code works great, my next question is how would I go about adding additional evaluates to that e.g. the same formula but for the row below it. I want one single msgbox to popup if any of the rows (I have about 10) make the formula true.

Thanks.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 34872072
>>"my next question is ..."
And hence, should be your next question... :)
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 34872160
BTW, are these formulas currently in use as CF formulas for the cells you want to test?
0
 

Author Comment

by:shoaibs
ID: 34872232
Yes, they are used as CF formulas
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 34872239
So which cells are you actually wanting to test?
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question