I am new to vba and need help in creating a custom function in Excel 2010. I will need a custom function since my ranges will change.
My data is as follows:
25 35 45 -5
50 -10 0 -5
50 -60 10 40
I need to create a function that will loop through each cell. If the sum of the first two cells is >= 0 then the function should grab the following cell and sum those three cells. The loop should end when the function reaches the end of the range. If the sum of the first two cells <0 then it should move to the next cell. For example the sum of the first row should be 100, the second row should be 45, and the third row should be 50.
This is how far I came to my code prior to getting stuck.
Public Function testloop(diff As Range) As Double
Dim c As Long
For c = 1 To diff.Columns.Count
If Cells(ActiveCell.Row, c) >= 0 Then
Aucun commentaire:
Enregistrer un commentaire