WorksheetFunction.SumIf Method

Adds the cells specified by a given criteria.

Namespace:  Microsoft.Office.Interop.Excel
Assembly:  Microsoft.Office.Interop.Excel (in Microsoft.Office.Interop.Excel.dll)

Syntax

'Declaration
Function SumIf ( _
    Arg1 As Range, _
    Arg2 As Object, _
    Arg3 As Object _
) As Double
'Usage
Dim instance As WorksheetFunction
Dim Arg1 As Range
Dim Arg2 As Object
Dim Arg3 As Object
Dim returnValue As Double

returnValue = instance.SumIf(Arg1, Arg2, _
    Arg3)
double SumIf(
    Range Arg1,
    Object Arg2,
    Object Arg3
)

Parameters

  • Arg2
    Type: System.Object

    Criteria - the criteria in the form of a number, expression, or text that defines which cells will be added. For example, criteria can be expressed as 32, "32", ">32", or "apples".

  • Arg3
    Type: System.Object

    Sum_range - the actual cells to add if their corresponding cells in range match criteria. If sum_range is omitted, the cells in range are both evaluated by criteria and added if they match criteria.

Return Value

Type: System.Double

Remarks

Sum_range does not have to be the same size and shape as range. The actual cells that are added are determined by using the top, left cell in sum_range as the beginning cell, and then including cells that correspond in size and shape to range. For example:

If range is

And sum_range is

Then the actual cells are

A1:A5

B1:B5

B1:B5

A1:A5

B1:B3

B1:B5

A1:B4

C1:D4

C1:D4

A1:B4

C1:C2

C1:D4

You can use the wildcard characters, question mark (?) and asterisk (*), in criteria. A question mark matches any single character; an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) preceding the character.

See Also

Reference

WorksheetFunction Interface

WorksheetFunction Members

Microsoft.Office.Interop.Excel Namespace