enfantter
03-28-2008, 02:30 AM
Hi all,
I trying to create an excel formula which is able to to sum a column(vertically) if two condition are fulfilled - these conditions are enteres in column 1 and 3 in the range ...
here is the code
Function betsum(rg, navn, status)
Dim rg As Range
Dim navn As String
Dim status As String
For Each Row In rg
For i = 0 To rg.lastrow.RowCount
If Cells(i, 1) = navn And Cells(i, 3) = status Then
tilsum(i) = Cells(i, 2).Value
End If
Next i
Next Row
betsum() = Sum(tilsum(i)) 'for all i's
End Function
It appears that my code has a flaw ... but i cannot find it - anybody sees it?!
I trying to create an excel formula which is able to to sum a column(vertically) if two condition are fulfilled - these conditions are enteres in column 1 and 3 in the range ...
here is the code
Function betsum(rg, navn, status)
Dim rg As Range
Dim navn As String
Dim status As String
For Each Row In rg
For i = 0 To rg.lastrow.RowCount
If Cells(i, 1) = navn And Cells(i, 3) = status Then
tilsum(i) = Cells(i, 2).Value
End If
Next i
Next Row
betsum() = Sum(tilsum(i)) 'for all i's
End Function
It appears that my code has a flaw ... but i cannot find it - anybody sees it?!