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)`.
Here is what I would use, I dont know any of the cell placement you have used so you will need to change that yourself.

Future reference this isnt a code writing site for you, if you are new to VBA i suggest doing simple stuff first, make a message box appear, use code to move to different cells, try a few if statments and/or loops. When your comftable with that start using varibles(Booleans, string , intergers and such) and you will see how far you can go. As i like to say , "if you can do it in excel, code can do it better"

If the code doesnt work or doesnt suit your needs then change it so it does, it worked for me when i used it but im not you nor do i have your spread sheet

paste it into your vba and use F8 to go through it step by step see how it works and if you want to use it.

```
Sub test()

[A1].Select ' assuming it starts in column A1

'loops till it reachs the end of the cells or till it hits a blank cell
Do Until ActiveCell.Value = ""

ActiveCell.Offset(0, 1).Select

'adds up the value of the cells going right and removes the previous cell to clean up
Do Until ActiveCell.Value = ""
x = x + ActiveCell.Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Offset(0, -1).ClearContents
Loop

'goes back to the begining and ends tallyed up value
Selection.End(xlToLeft).Select
ActiveCell.Offset(0, 1).Value = x

'moves down one to next row
ActiveCell.Offset(1, 0).Select

Loop

End Sub

```