我正在使用SumIf
函數將所有包含字符串dailyTotal
的單元格合計到它們的左側。然後我在Macros
表單上設置單元格C29
爲該值,並將其與數字進行比較以查看接下來執行的代碼。我在E列單元格的值,但價值總是返回爲0SumIf值始終返回爲0 - Excel VBA
代碼:
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
的SUMIF公式是錯誤的:SUM(RANGE ,標準,[RANGE_TO_SUM])。你想要使用整個範圍而不是單個單元格。你有兩個標準,字符串''日常總計:''和''''你能顯示一些測試數據和預期結果嗎? –
調整到一個評論,因爲這只是部分:刪除此行:「表(」宏「)。範圍(」C29「)= totalHours」 – Zerk