Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

Excel: refer to the fields in every row of a range passed

$
0
0

I have a spreadsheet with a couple of sets of periodical expenses and the times per year they happen, like this example:

12  € 422,88
12  € 423,60
12  € 1.576,80
1   € 33,84
4   € 30,00
12  € 852,00

Every record where the first column is 12 denotes a montly expense, a 1 means a yearly and a 4 a quarterly expense. Now I would like to make a monthly reservation for all the non-monthly expenses by adding every record's amount where the first column is not 12 and dividing the sum by 12.

I'm trying to do this by iterating over a range with both columns, like this:

Function Reserve(expenses As Range) as Currency
  Dim row As Range
  Dim total As Integer

  total = 0
  For Each row In expenses
    if row.Cells(0).Value2 != 12 Then Total += row.Cells(1).Value2
  Next row
  Reserve = total / 12
End Function

This problem is that the row.Cells(0).Value2 is not accepted. How do I refer to the two fields in every row of the range passed?

Thanks for any help!


Viewing all articles
Browse latest Browse all 88030

Trending Articles