SumIf值始终返回0 - Excel VBA

时间:2017-01-20 17:02:36

标签: excel vba sumifs

我正在使用SumIf函数将所有包含字符串dailyTotal的单元格添加到它们的左侧。然后,我在C29工作表上将单元格Macros设置为该值,并将其与数字进行比较,以查看下一步执行的代码。我在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

1 个答案:

答案 0 :(得分:1)

你可能在此之后

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 ...