2

I am trying to write a function in Excel that:

  1. Iterates through each worksheet
  2. Checks if the supplied string exists in the supplied cell
  3. 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
4

1 回答 1

2

在使用它们之前,您需要为rowcol建立值。

于 2013-11-06T19:24:38.830 回答