"Argument not optional" how do i deal with this

  • i keep getting this error when i am tring to call this function


    Function totalitems(totalitems)
    UserRowCounter = UserStartRow
    While Worksheets("Log-Import").Cells(UserRowCounter, UserStartCol) <> ""
    UserRowCounter = UserRowCounter + 1
    Wend
    totalitems = UserRowCounter
    End Function



    'function to be the do all end all find logoff for each coresponding logon.


    Function Findlogoff(totalitems)
    itemcount = 0
    totalitems (totalitems)
    For counter = 1 To totalitems
    If LogCol = "logoff" Then
    If UsernameCol = username Then
    If DayCol = UserDayCol Then
    Worksheet(username).Cells(userrow, UserLogoffCol).Value = Worksheets("log-import").Cells(logrow, LogCol).Value
    itemcount = itemcount + 1
    End If
    End If
    End If


    Next counter
    If itemcount = 0 Then
    MsgBox "there were no logoffs found for & username & on that day. would you like to continue."
    End If

    End Function



    'Call a logoff function here

    Findlogoff (totalitems)


    please help this is the last thing i need i promise

  • I suspect the problem is with
    Function totalitems(totalitems)
    The argument totalitems is also the name of the function, so it is trying to call itself but can't because it doesn't have an argument in the second call. It doesn't appear that the function actually needs an argument, so try it just as
    Function totalitems

  • ok i lied i got one more probelm and that is a darn type mismatch


    lastrow = totalitems(userstartrow)


    i am tring to call the function so i can use it in my for loop but i am gettign the mismatch problem so if you could help that would be great

  • Hi bourassa,


    I should image poor old Excel is completly confused by the fact you are using the same name for a function and a variable.


    totalitems as a function expects an argument.


    Therefore when you use totalitems as a variable the compiler is fooled into thinking its a function called totalitems and requires a argument.


    Try renaming the function GetTotalitems.


    Actually the function does not require a variable at all.
    Try this,


    Function GetTotalitems()
    userrowcounter = userstartrow
    While Worksheets("Log-Import").Cells(userrowcounter, userstartcol) <> ""
    userrowcounter = userrowcounter + 1
    Wend
    GetTotalitems = userrowcounter
    End Function


    Function Findlogoff(totalitems)
    itemcount = 0
    totalitems = GetTotalitems()
    For counter = 1 To totalitems
    If logcol = "logoff" Then
    If usernamecol = username Then
    If daycol = userdaycol Then
    Worksheet(username).Cells(userrow, userlogoffcol).Value = Worksheets("log-import").Cells(logrow, logcol).Value
    itemcount = itemcount + 1
    End If
    End If
    End If
    Next counter
    If itemcount = 0 Then
    MsgBox "there were no logoffs found for " & username & " on that day. would you like to continue."
    End If
    End Function


    Depending on the rest of the code you might not even need to pass Findlogoff a variable.


    Cheers
    Andy

    [h4]Cheers
    Andy
    [/h4]

  • wow man u are the best but there a still just a few thnks that need to be tweeked one is
    If LogCol = "logoff" Then
    i get a type mis match with that and how should i call it in the main program, i am calling it like this now



    'Determine the next available user row
    userrow = UserRowFinder(username)
    'Enter the value of this user row to the appropriate user's sheet
    Worksheets(username).Cells(userrow, UserDayCol).Value = Worksheets("Log-Import").Cells(logrow, DayCol).Value
    Worksheets(username).Cells(userrow, UserDateCol).Value = Worksheets("Log-Import").Cells(logrow, DateCol).Value
    Worksheets(username).Cells(userrow, UserLogonCol).Value = Worksheets("Log-Import").Cells(logrow, TimeCol).Value
    'Call a logoff function here

    Findlogoff (totalitems)


    your imput is great thanks for all your help so far

Participate now!

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