So I wrote a simple function in VBA and I want to use it in my excel workbook. I wrote the following code:
Option Explicit
Public Function KOLICINA(fiksnacena As Long, ceni() As Long, nedela() As Long) As Long
Dim brojac As Integer
For brojac = 1 To UBound(nedela)
If Not ((IsEmpty(nedela(brojac) Or nedela(brojac) = 0) And ceni(brojac) <> fiksnacena)) Then KOLICINA = nedela(brojac)
Next brojac
End Function
When I try to use it in a worksheet cell (using =KOLICINA(18;G22:G26;H22:H26))
, I get the #VALUE error.
I don't understand why. The function should go through nedela Array and if it finds a Non empty or different value than 0 AND if the matching cell in the ceni Array is different from the number fiksnacena, it should return the value of the cell in nedela.
ceni()andnedela()toRangeinstead ofLong?Then KOLICINA = nedela(brojac)could perhaps be replaced byThenfollowed byKOLICINA = nedela(brojac)followed byExit Functionfollowed byEnd If. Once you find the return value, why continue the loop (unless you want the last match)?If Not (IsEmpty(nedela(brojac)) Or nedela(brojac) = 0) And ceni(brojac) <> fiksnacena Then.Emptylong, so I don't see the point of theisEmptytest on the elements of an array of longs