Reputation: 35
I'm trying to make my own function in VBA-Excel 2010 to count some things in array passed as function arg. Also 2 conditions are passed too. The problem is I can't get Ubound() function to work.
Here's the code:
Function IleGier(Arr As Variant, Champ As String, Data As Date) As Variant 'Integer
' arr/\ cond1/\ cond2/\
Dim i As Integer
Dim ile As Integer
ile = -1
i = 1
Do While i < UBound(Arr, 1)
If Arr(1)(i) = Data Then
If Arr(2)(i) = Champ Then
ile = ile + 1
End If
End If
i = i + 1
Loop
IleGier = ile
'IleGier = Arr(2)(1)
End Function
Array will always be 2 dimensional.
ex. array:
15-3-2013 Arg1
15-3-2013 Arg2
15-3-2013 Arg1
15-3-2013 Arg1
16-3-2013 Arg3
16-3-2013 Arg3
16-3-2013 Arg1
Desired return for =IleGier(E1:F10;"Arg1";"15-3-2013")
would be 3 (Date arg in this ex. might be passed wrong bcoz of ""), but it returns #ARG
as long I use UBound()
function.
Any tips?
Upvotes: 1
Views: 5209
Reputation: 328618
i
being the second index, I guess you should use:
Do While i < UBound(Arr, 2)
Upvotes: 4