SumIf 值始终 returns 为 0 - Excel VBA
SumIf value always returns as 0 - Excel VBA
我正在使用 SumIf
函数将其左侧包含字符串 dailyTotal
的所有单元格相加。然后,我将 Macros
sheet 上的单元格 C29
设置为该值,并将其与数字进行比较以查看接下来执行的代码。我在 E 列单元格中有值,但值始终 returns 为 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 ...
我正在使用 SumIf
函数将其左侧包含字符串 dailyTotal
的所有单元格相加。然后,我将 Macros
sheet 上的单元格 C29
设置为该值,并将其与数字进行比较以查看接下来执行的代码。我在 E 列单元格中有值,但值始终 returns 为 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 ...