希望有人可以幫助我解決以下問題,我在我的 VBA 代碼中使用了 SUMIFS 公式,它適用于值,除非我試圖查找空白。
示例源資料集:
| 日期(原始表格中的 G 欄) | 客戶(原始表格中的 O 欄) | TransactionValue(原始作業表中的 E 列) |
|---|---|---|
| 格林威治標準時間 2021-02-26 05:45:00 | 100 | |
| 格林威治標準時間 2021-02-26 05:45:00 | 約翰多 | 20 |
| 格林威治標準時間 2021-02-26 07:12:18 | 約翰多 | 15 |
| 格林威治標準時間 2021-02-26 07:12:18 | 75 | |
| 格林威治標準時間 2021-02-26 12:22:55 | 簡多 | 28 |
| 格林威治標準時間 2021-02-26 12:22:55 | 喬博客 | 85 |
然后,我基本上構建了一些看起來有點像資料透視表的東西,所需的輸出是每個客戶在每個時間戳中的總和:
| 日期 | 約翰多 | 簡多 | 喬博客 | |
|---|---|---|---|---|
| 格林威治標準時間 2021-02-26 05:45:00 | 100 | 20 | ||
| 格林威治標準時間 2021-02-26 07:12:18 | 75 | 15 | ||
| 格林威治標準時間 2021-02-26 12:22:55 | 28 | 85 |
下面是我的代碼:
Dim r as Range
Dim finalcolumn as Long
finalcolumn = ActiveSheet.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Set r = Cells(2, 2)
With r
.Formula = "=SUMIFS(Results!$E:$E,Results!$O:$O,Static2!B$1,Results!$G:$G,Static2!$A2)"
.AutoFill Destination:=Range(Cells(2, 2), Cells(2, finalcolumn))
End With
我的問題是這不會為第二列回傳任何內容,即 Customer 為空白。它適用于所有其他客戶名稱。
請問有什么想法嗎?
uj5u.com熱心網友回復:
試試這個:
.Formula = "=SUMIFS(Results!$E:$E,Results!$O:$O,IF(Static2!B$1="""","""",Static2!B$1),Results!$G:$G,Static2!$A2)"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/480552.html
