SumIf值始终返回为0 – Excel VBA

我正在使用SumIf函数将包含stringdailyTotal所有单元格添加到它们的左侧。 然后,我在Macros表上设置单元格C29为该值,并将其与一个数字进行比较,以查看接下来执行的代码。 我有在E列单元格中的值,但值始终返回为0。

码:

 dailyTotal = "Daily Total:" Dim totalHours As Double Dim rng As Range: Set rng = Application.Range("Totals!E11:E100") Dim cell As Range For Each cell In rng.Cells With Sheets("Totals") Sheets("Macros").Range("C29").Formula = Application.SumIf(cell.Offset(, -1), dailyTotal, "") Sheets("Macros").Range("C29") = totalHours End With Next cell ' check if command is applicable If totalHours > 4 Then 

你可能会在这之后

 Dim totalHours As Double Dim dailyTotal As String: dailyTotal = "Daily Total:" Dim rng As Range: Set rng = Application.Range("Totals!E11:E100") totalHours = Application.SumIf(rng.Offset(, -1), dailyTotal, rng) Sheets("Macros").Range("C29") = totalHours ' check if command is applicable If totalHours > 4 Then ...