VBA - 宏在我不想要它时添加它们时会舍入我的值

时间:2016-04-27 16:59:49

标签: vba

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。

0 个答案:

没有答案