I am trying to write a function in Excel that:
- Iterates through each worksheet
- Checks if the supplied string exists in the supplied cell
- Adds a predetermined cell value to the return value if step 2 evaluates to True
I've been stepping through my function and am getting the correct values until the function has to add the 4th cell to my return value.
Anyone have any idea what's going on? Thanks!
Function Revenue(row As Integer, col As Integer, str As String) As Integer
Dim i As Integer
For i = 2 To Worksheets.Count
If Worksheets(i).Cells(row, col) = str Then
Revenue = Revenue + Worksheets(i).Cells(21, 2) // Bug occurs on 4th iteration
Debug.Print Revenue
End If
Next i
End Function