borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Opening USB Port for Printing)Next Topic (command button to find text on another sheet) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : please help ---- isMissing Solved Topic
Poster Message
justarrive
Level: Protégé

Registered: 18-10-2005
Posts: 6

icon please help ---- isMissing

Folks,
    I have a problem of using isMissing to check if an optional range is missing. In every case, the result of isMissing function returns not missing and the result of the calculation is incorrect. Below is the code. Please help.
   Thanks in advance.
----
Function myCal(m As Range, Optional r As Range) As integer

    If IsMissing(r) = True Then
        myCal = WorksheetFunction.Sum(m.Rows.Value)
    Else
        myCal = WorksheetFunction.SumProduct(m.Rows.Value, r.Rows.Value)
    End If
End Function

[Edited by justarrive on 20-10-2005 at 06:08 PM GMT]

20-10-2005 at 06:07 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: please help ---- isMissing

Hi,
Looks like the check should be "r is nothing". I don't know why, but Excel is passing nothing into the "r" parameter.
Try the following:

Public Function myCal(m As Range, Optional r As Range) As Integer

    If r Is Nothing Then
        myCal = WorksheetFunction.Sum(m.Rows.Value)
    Else
        myCal = WorksheetFunction.SumProduct(m.Rows.Value, r.Rows.Value)
    End If
End Function


Hope this helps,
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

23-10-2005 at 10:22 PM
View Profile Send Email to User Show All Posts | Quote Reply
justarrive
Level: Protégé

Registered: 18-10-2005
Posts: 6
icon Re: please help ---- isMissing

totally works. thanks so much.

24-10-2005 at 07:53 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: please help ---- isMissing

Hi JS,
Can you mark this as solved if it is pls?
Ta
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

24-10-2005 at 11:16 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : please help ---- isMissing Solved Topic
Previous Topic (Opening USB Port for Printing)Next Topic (command button to find text on another sheet) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder