Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBA Run-Time Error 13

Posted on 2011-02-11
10
Medium Priority
?
329 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

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!

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

722 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