function within a function (help)

  • Hi,


    I dont understand why the following codes dont run properly


    Function GetSettlementData(SettlementDate, DeliveryDate, Prod, Timeframe)
    If Timeframe = "Monthly" And Prod = "Power" Then
    With Sheets("Settlement Data")
    RowIndex = WorksheetFunction.Match(SettlementDate, .Range("A160:A312"), False)
    ColIndex = WorksheetFunction.Match(DeliveryDate, .Range("B159:W159"), False)
    GetSettlementData = WorksheetFunction.Index(.Range("B160:W312"), RowIndex, ColIndex)

    End With
    End If

    End Function


    Basically, RowIndex and ColIndex are outputs of the function match, and they should be some numeric value. So I feed them into the function Index but it does not properly give me back the correct answer i'm looking for.


    What is the problem?


    Thanks,
    Kim

  • Have you run the function with debug to make sure that you are getting the correct value for RowIndex and ColIndex?


    You may want to return some default value if TimeFrame is not Monthly and Prod is not Power.


    Care to post a small version of the workbook?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!