Function avgProcessTime(FDate As Date, LDate As Date, totLocal As String)
Dim cnt As Long
Dim i As Long
Dim sh As Worksheet
Dim sum As Long
Dim test As Worksheet
'Designate variables for worksheets
Set sh = ThisWorkbook.Worksheets("DATA")
Set test = ThisWorkbook.Worksheets("test")
'Set counts to zero
cnt = 0
sum = 0
'Loop through the rows
For i = 1 To sh.UsedRange.Rows.Count
'Count the time of the process if its between set dates
If sh.Cells(i, 2).Value <= (LDate) And sh.Cells(i, 8).Value <> "" And _
sh.Cells(i, 2).Value >= (FDate) And sh.Cells(i, 8).Value <> 0 Then
sum = sum + sh.Cells(i, 8).Value
cnt = cnt + 1
Else
End If
Next i
'Find the avergae of the process
test.Range(totLocal).Value = sum / cnt
End Function
由于这个原因,答案是.5。试图修复它,以便宏不会圆,但我是VBA的新手。当它在AverageIFS内总和时,它是307.75204。宏是304。