返回列表 上一主題 發帖

利用日期來加總當日金額出錯

回復 3# coafort
謝謝前輩發表此主題
請前輩試試看
1.AO3:AO39格式設為yyyy/m/d;@
2.AO3設公式 =IF(AS3="","",TODAY())
3.下刷到AO39
TEST_20220923-1.zip (25.09 KB)


今日習得=SUMPRODUCT()
  1. Option Explicit
  2. Sub TEST_1()
  3. '[AS3:AS39]變更 觸發
  4. '讓[AO3:AO39]今天日期的AO底色不同,對應[BG46:BG82]底色不同也不同
  5. '只總計[AO3:AO39]是今日的,對應[BG46:BG82]數值在BG2
  6. Application.ScreenUpdating = False
  7. Dim i
  8. [BG2] = ""
  9. For i = 3 To 39
  10.    If Cells(i, "AO") = Date Then
  11.       Cells(i, "AO").Interior.ColorIndex = 17
  12.       Cells(i, "BG").Item(44, 1).Interior.ColorIndex = 17
  13.       [BG2] = [BG2] + Cells(i, "BG").Item(44, 1)
  14.       Else
  15.          Cells(i, "AO").Interior.ColorIndex = xlNone
  16.          Cells(i, "BG").Item(44, 1).Interior.ColorIndex = xlNone
  17.    End If
  18. Next
  19. End Sub
  20. Sub TEST_2()
  21. '[AS3:AS39]變更 觸發
  22. '讓[AO3:AO39]今天日期的AO底色不同,對應[BG46:BG82]底色不同也不同
  23. '只總計[AO3:AO39]是今日的,對應[BG46:BG82]數值在BG2
  24. Application.ScreenUpdating = False
  25. Dim i As Range, Y
  26. Set Y = CreateObject("Scripting.Dictionary")
  27. [BG2] = ""
  28. For Each i In Range([AO3], [AO82])
  29.    Y.Add i, i.Item(44, 19)
  30.    If i = Date Then
  31.       i.Interior.ColorIndex = 35
  32.       i.Item(44, 19).Interior.ColorIndex = 35
  33.       [BG2] = [BG2] + Y(i)
  34.       Else
  35.          i.Interior.ColorIndex = xlNone
  36.          i.Item(44, 19).Interior.ColorIndex = xlNone
  37.    End If
  38. Next
  39. End Sub
  40. Sub TEST_3()
  41. '[AS3:AS39]變更 觸發
  42. '讓[AO3:AO39]今天日期的AO底色不同,對應[BG46:BG82]底色不同也不同
  43. '只總計[AO3:AO39]是今日的,對應[BG46:BG82]數值在BG2
  44. Application.ScreenUpdating = False
  45. Dim R&, Y, Z As Range, xR As Range
  46. Set Y = CreateObject("Scripting.Dictionary")
  47. [BG2] = ""
  48. Set Z = Range([AO3], [BG82])
  49. Z.Interior.ColorIndex = xlNone
  50. For Each xR In Z
  51.    Y(xR.Value) = Y(xR.Value) + xR.Item(44, 19).Value
  52.    If xR = Date Then
  53.       xR.Interior.ColorIndex = 38
  54.       xR.Item(44, 19).Interior.ColorIndex = 38
  55.    End If
  56. Next
  57. [BG2] = Y(Date)
  58. End Sub
複製代碼

TOP

        靜思自在 : 【蒙蔽的自由】人常在什麼都可以自由自在的時候,卻被這種隨心所欲的自由蒙蔽,虛擲時光而毫無覺知。
返回列表 上一主題