Solved

Excel Run-time error '13'

Posted on 2011-09-02
7
169 Views
Last Modified: 2012-06-21
Hello Experts,

Can someone please tell me why I keep on getting a Run-time error, Type mismatch when I open my spreadsheet with the following code. When click on debug it highlights the following:

 If Stocks(i) <> .Value Then




Private Sub Worksheet_Calculate()
Dim cel As Range
Dim Addr As Variant, Targ As Variant
Static Stocks(3) As Double      'Starts with element 0
Dim i As Long, n As Long
Addr = Array("AQ3", "AV3", "AP3", "AU3")    'Watch these cells for price changes
Targ = Array(85, 85, 20, 20)                'Look for prices above these threshhold values
n = UBound(Stocks)
For i = 0 To n
    With Range(Addr(i))
        If Stocks(i) <> .Value Then
            Stocks(i) = .Value
            If .Value > Targ(i) Then
                Open "C:\Users\User\Documents\ABC.txt" For Append As #1  'Change path & name to suit
                Write #1, .Address(False, False), .Value, Date, Format(Time, "hh:mm:ss.ss")
                Close 1
            End If
        End If
    End With
Next
End Sub

Open in new window



Cheers
0
Comment
Question by:cpatte7372
[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
  • 3
  • 3
7 Comments
 

Author Comment

by:cpatte7372
ID: 36472608
For the Experts willing to assist the attached spreadsheet my provide further assistance.

Cheers
EE-TypeMismatch.xlsm
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36472762
It's because AU3 contains a #DIV/0! error and therefore is not numeric. You coulod add a check to your code as follows:
Private Sub Worksheet_Calculate()
Dim cel As Range
Dim Addr As Variant, Targ As Variant
Static Stocks(3) As Double      'Starts with element 0
Dim i As Long, n As Long
Addr = Array("AQ3", "AV3", "AP3", "AU3")    'Watch these cells for price changes
Targ = Array(85, 85, 20, 20)                'Look for prices above these threshhold values
n = UBound(Stocks)
For i = 0 To n
    With Range(Addr(i))
        If Not IsError(.Value) Then
            If Stocks(i) <> .Value Then
                Stocks(i) = .Value
                If .Value > Targ(i) Then
                    Open "C:\Users\User\Documents\ABC.txt" For Append As #1  'Change path & name to suit
                    Write #1, .Address(False, False), .Value, Date, Format(Time, "hh:mm:ss.ss")
                    Close 1
                End If
            End If
        End If
    End With
Next
End Sub

Open in new window


0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36472769
Actually you might also want to check that it is numeric, as a non-numeric value would also cause your code to fail.  You could add an IF statement inside the error check like:

If Isnumeric(.Value) Then  .....
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:cpatte7372
ID: 36472841
Andrew,

You're code seemed to have done the trick cheers mate
0
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 500 total points
ID: 36472862
Good - happy to help... but I'd still like the points (and for the conditional formatting one I answered for you earlier)  ;-)
0
 

Author Closing Comment

by:cpatte7372
ID: 36519710
Hi sorry for the delay in awarding points.

Cheers mate.
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

Suggested Solutions

Title # Comments Views Activity
EXCEL Name Matching 13 48
Pivot tables that only has data for one section - how to do it.. 4 45
using vb script 5 52
Excel Pivot Table question 5 17
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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!
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
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.

730 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