Whats wrong with my code? Keep getting arguments not optional error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • irongollem
    New Member
    • May 2013
    • 2

    Whats wrong with my code? Keep getting arguments not optional error

    Below is the function I defined. It is supposed to calculate the amount of payment terms between two dates (rounded up) and do this according to a dropdown menu that gives users the option to select monthly, quarterly or yearly payments. Functions first argument is the result of this dropdown, the second argument is the first date and the third argument is the last date or end date for this specific payment plan.
    The error message I'm getting is that the arguments aren't optional. The weird thing is that in excel im filling al the arguments (with cells in the form of
    "Termijnbereken ing(C4;D4;F4)"

    But it still gives me the error. Below my code:


    Code:
    Function Termijnberekening(Termijn As Variant, Ingangsdatum As Date, Einddatum As Date) As Integer
        If Termijn = "Maand" Then
            Termijnberekening = (Year(Einddatum) - Year(Ingangsdatum)) * 12 + Month(Einddatum) - Month(Ingangsdatum)
        ElseIf Termijn = "Kwartaal" Then
            Termijnberekening = (Year(Einddatum) - Year(Ingangsdatum)) * 4 + WorksheetFunction.RoundUp((Month(Einddatum) - Month(Ingangsdatum)) / 3)
        ElseIf Termijn = "Jaar" Then
            Termijnberekening = (Year(Einddatum) - Year(Ingangsdatum))
        Else
            Termijnberekening = "Kies Termijn Type"
    End Function
    Last edited by Rabbit; May 31 '13, 04:38 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    Your thread has been moved to the Excel forum, you were in the wrong one.

    The problem is line 5. The WorksheetFuncti on.RoundUp() function requires two arguments. The second argument is the number of digits to which you want to round the number.

    Comment

    • irongollem
      New Member
      • May 2013
      • 2

      #3
      Ah thanks, Im a total novice to VBA and the debugger highlighted the first line which led me to think the error was in there.

      Comment

      Working...