-1

enter code herei try to sum all positive value in my array but every time object not found or parameter misssing error seen.

Option Explicit

Sub trail2()
    With ThisWorkbook
        Dim arr1 As New ArrayList
        arr1.Add 20
        arr1.Add -15
        arr1.Add 20.77
        msgbox  Application.WorksheetFunction.CountIf(arr1, ">0")
    end with
end sub

error = object not found or parameter misssing error seen

i also try on range but thats also not working

Option Explicit
Sub trail2()
dim rr as variant
dim i as variant
 With ThisWorkbook
 rr = Range(.Sheets("data").Cells(2, 5), .Sheets("data").Cells(4, 5))
 msgbox Application.WorksheetFunction.CountIf(rr, ">0")
end with
end sub

same data as per array but error seen. error = object required i don't want that sheet data so i need only array for sumif. how to slove it ?

1 Answers1

1

When assigning a range to a variable, you need to use Set

You should also use the worksheet your range is on to avoid it pulling from an active sheet.

Option Explicit
Sub trial2()

Dim rr As Range

Dim i As Variant

    With ThisWorkbook.Sheets("Data")
        Set rr = .Range(.Cells(2, 5), .Cells(4, 5))
        MsgBox Application.WorksheetFunction.CountIf(rr, ">0")
    End With
End Sub
Kavorka
  • 306
  • 3
  • 10