+ Reply to Thread
Results 1 to 3 of 3

Runtime error 13 - type mismatch

Hybrid View

  1. #1
    Registered User
    Join Date
    05-24-2014
    Posts
    3

    Runtime error 13 - type mismatch

    Hello,

    I have a VBA code that run for a set of data(all in numbers). The code is totally fine when it is run for the first time. But when I run it again, the error - "type mismatch" will come out. When I open a new excel workbook and paste all the data and code into it, it works at the first time. But the error will pop up again if i run for the second time. Can anyone help to solve?
    Thanks a lot for the help!

    My code is as below: (the red line is where the error message pop out)

    Sub LinestTest2()
    Dim vCoeff As Variant, vY As Variant, vX As Variant
    Dim i As Variant, j As Variant, h As Variant, t As Variant
     
    ReDim vY(1 To 101, 1 To 1)
    ReDim vX(1 To 101, 1 To 37)
    
    For t = 15 To 86
    
        For j = 1 To 101
            vY(j, 1) = Cells(179 + j, 5)
        Next
     
        For i = 1 To 101
            For h = 1 To 18
                vX(i, h) = Cells(179 + i, 8 + h)
            Next
        Next
    
        For i = 1 To t - 1
            vX(i, 19) = 0
        Next
        
        For i = t To 101
            vX(i, 19) = 1
        Next
        
        For i = 1 To t - 1
            For h = 20 To 37
                vX(i, h) = Cells(179 + i, 8 + h) * 0
            Next
        Next
        
        For i = t To 101
            For h = 20 To 37
                vX(i, h) = Cells(179 + i, 8 + h) * 1
            Next
        Next
    
        vCoeff = Application.WorksheetFunction.LinEst(vY, vX, , True)
     
        Cells(179 + t, 30) = vCoeff(3, 1)
        
        For i = 1 To 101                    'To have a blank vX to load data in next loop
            For h = 1 To 37
                vX(i, h) = 0
            Next
        Next
     
    Next
     
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Runtime error 13 - type mismatch

    Hi,

    Possibly try changing
    Cells(179 + i, 8 + h) * 0
    to
    Cells(179 + i, 8 + h).Value * 0
    or simply just 0 (if you are multiplying by 0, you may as well skip the multiplication step...).

    My hopes aren't high for this as a solution, but if it doesn't work please upload your workbook (or a usable sample) so that I can debug the code in its original context.

    Thanks

  3. #3
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Runtime error 13 - type mismatch

    Your purpose in multiplying by zero is unclear. Seems either to produce a zero, in which case you'd be better doing that directly, or to check if any non-numbers occur in your data.

    A cause for type mismatch error is trying to multiply a non-number (other than a blank) by a number (including zero).

    Track it down a bit more by replacing your red line by
    With Cells(179 + i, 8 + h)
        If Not IsNumeric(.Value) Then
            MsgBox .Address & "    " & .Value
            Exit Sub
        Else
            vX(i, h) = .Value * 0
            'or just vX(i, h) = 0
        End If
    End With

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Type Mismatch Runtime Error
    By Jaeger in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-21-2014, 10:49 AM
  2. [SOLVED] runtime error 13 type mismatch
    By chappie in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-30-2012, 10:12 PM
  3. Runtime Error 13 Type Mismatch
    By vtsoldier2010 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2012, 12:59 PM
  4. Runtime Error 13 - type mismatch
    By hindlehey in forum Excel General
    Replies: 1
    Last Post: 11-07-2005, 10:55 AM
  5. Runtime Error '13': Type mismatch
    By Linking to specific cells in pivot table in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2005, 03:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1