As a complete beginner to VBA Excel, I would like to be able to do the following:

I want to find the first value larger than 0 in a row, and then sum over the following 4 cells in the same row. So

```
Animal1    0    0    1    2    3    0    1
Animal2    3    3    0    1    4    2    0
Animal3    0    0    0    0    0    1    0

```

Results in

```
Animal1    7
Animal2    11
Animal3    1

```

Is this possible?
['https://Stackoverflow.com/questions/34811616', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4729787/']
(Your problem description didn't match your examples. I interpreted the problem as one of summing the 4 elements in a row which begin with the first number which is greater than 0. If my interpretation is wrong -- the following code would need to be tweaked.)

You could do it with a user-defined function (i.e. a UDF -- a VBA function designed to be used as a spreadsheet function):

```
Function SumAfter(R As Range, n As Long) As Variant
    'Sums the (at most) n elements beginning with the first occurence of
    'a strictly positive number in the range R,
    'which is assumed to be 1-dimensional.
    'If all numbers are zero or negative -- returns a #VALUE! error

    Dim i As Long, j As Long, m As Long
    Dim total As Variant

    m = R.Cells.Count
    For i = 1 To m
        If R.Cells(i).Value > 0 Then
            For j = i To Application.Min(m, i + n - 1)
                total = total + R.Cells(j)
            Next j
            SumAfter = total
            Exit Function
        End If
    Next i
    'error condition if you reach here
     SumAfter = CVErr(xlErrValue)
End Function

```

If your sample data is in `A1:H3` then putting the formula `=SumAfter(B1:H1,4)` in `I1` and copying down will work as intended. Note that the code is slightly more general than your problem description. If you are going to use VBA, you might as well make your subs/functions as flexible as possible. Also note that if you are writing a UDF, it is a good idea to think of what type of error you want to return if the input violates expectations. See [this](http://www.cpearson.com/Excel/ReturningErrors.aspx) for an excellent discussion (from Chip Pearson's site - which is an excellent resource for Excel VBA programmers).

ON EDIT: If you want the first cell greater than 0 added to the next 4 (for a total of 5 cells in the sum) then the function I gave works as is, but using `=SumAfter(B1:H1,5)` instead of `=SumAfter(B1:H1,4)`.
This is the one of the variants of how you can achieve required result:

```
 Sub test()
        Dim cl As Range, cl2 As Range, k, Dic As Object, i%: i = 1
        Set Dic = CreateObject("Scripting.Dictionary")
        For Each cl In ActiveSheet.UsedRange.Columns(1).Cells
            For Each cl2 In Range(Cells(cl.Row, 2), Cells(cl.Row, 8))
                If cl2.Value2 > 0 Then
                    Dic.Add i, cl.Value2 & "|" & Application.Sum(Range(cl2, cl2.Offset(, 4)))
                    i = i + 1
                    Exit For
                End If
        Next cl2, cl
        Workbooks.Add: i = 1
        For Each k In Dic
            Cells(i, "A").Value2 = Split(Dic(k), "|")(0)
            Cells(i, "b").Value2 = CDec(Split(Dic(k), "|")(1))
            i = i + 1
        Next k
    End Sub

```

[![enter image description here](https://i.stack.imgur.com/rviN2.png)](https://i.stack.imgur.com/rviN2.png)