+ Reply to Thread
Results 1 to 4 of 4

Type Mismatch Errors...

Hybrid View

  1. #1
    Registered User
    Join Date
    05-21-2007
    Posts
    79

    Type Mismatch Errors...

    I keep getting type mismatch errors here, and I'm not sure why...

    Sub GetYields(ByVal g As Long)
    
        Workbooks.Open ("S:\H062\seg130\GIC\GetRatesTesterFile.xls")
        Workbooks("hard work tester file.xls").Worksheets("Sheet2").Activate
        If g > 8 Then
            For y = 2 To g - 2
                Cells(g + y - 1, 11).Value = Switch(y = 2, 1, y = 3, 2, y = 4, 3, y = 5, 4, y = 6, 5, y = 7, 10)
                Cells(g + y - 1, 12).Value = AutoAssign(ByVal y)
            Next y
        Else
            For k = 1 To 6
                Cells(g + k, 11).Value = Switch(k = 1, 1, k = 2, 2, k = 3, 3, k = 4, 4, k = 5, 5, k = 6, 10)
                Cells(g + k, 12).Value = AutoAssign(k + 1)
            Next k
        End If
    
    End Sub
    g is declared as a long for no good reason, but I left it that way. It's sent to this function ByVal. AutoAssign is a function that returns a long-type number from the Test.xls workbook. I don't understand why I'm getting an error at the first call of AutoAssign. It's telling me there's a type mismatch with y, in the function call.

    Any suggestions?

  2. #2
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    Try passing your variable to AutoAssign simply as y rather than ByVal y

    AutoAssign(y)

    HTH

  3. #3
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    I'm pretty sure you only use the byval when you are declaring a function / sub. So remove it from the function call and see how you go.


    rylo

  4. #4
    Registered User
    Join Date
    05-21-2007
    Posts
    79
    I figured it out... the function AutoAssign takes a Long type variable, and the declaration of y wasn't explicit. Once I declared y as Long it worked again.

    Thanks for the suggestions!

+ 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