+ Reply to Thread
Results 1 to 3 of 3

Type Mismatch??

Hybrid View

  1. #1
    Registered User
    Join Date
    03-02-2008
    Posts
    39

    Type Mismatch??

    I keep getting a "Type mismatch" error with the first execution line inside the FOR loop when I try to execute this code. What am I doing wrong? How can I correct it?

        Dim Ktire As Double
        Dim t As Variant
        Dim zfront As Variant
        Dim zrear As Variant
        ReDim t(1 To 86016, 1 To 1)  
        ReDim zfront(1 To 86016, 1 To 1)  
        ReDim zrear(1 To 86016, 1 To 1)
        
        t = Worksheets("Lists").Range("C15:C86030")
        zfront = Worksheets("Lists").Range("D15:D86030")
        zrear = Worksheets("Lists").Range("E15:E86030")
        
        Dim Ffront As Variant
        Dim Frear As Variant
        ReDim Ffront(1 To 86016, 1 To 1)
        ReDim Frear(1 To 86016, 1 To 1)
        
        For i = 1 To 86016
            Ffront(i, 1) = -Ktire * zfront(i, 1)
            Frear(i, 1) = -Ktire * zrear(i, 1)
        Next i
    Thanks in advance-

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Type Mismatch??

    Sub x()
        Dim Ktire       As Double
        Dim t           As Variant
        Dim zfront      As Variant
        Dim zrear       As Variant
        Dim i           As Long
    
        With Worksheets("Lists")
            t = .Range("C15:C86030").Value
            zfront = .Range("D15:D86030").Value
            zrear = .Range("E15:E86030").Value
        End With
    
        Dim Ffront      As Variant
        Dim Frear       As Variant
        ReDim Ffront(1 To 86016, 1 To 1)
        ReDim Frear(1 To 86016, 1 To 1)
    
        For i = 1 To 86016
            Ffront(i, 1) = -Ktire * zfront(i, 1)
            Frear(i, 1) = -Ktire * zrear(i, 1)
        Next i
    End Sub
    You'll get an error if the array zfront contains something other than a number.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,266

    Re: Type Mismatch??

    Suspect you hava a non-numeric character in column D.

    Is it the first time through the loop? If not, you'll need to look at the value of i to work out the offset for the array and, consequently, where the problem is in column D.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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