返回列表 上一主題 發帖

累計加總數量及每週加總數量

回復 6# yen956
  1. '3月1日的前一天, 即為2月的最後一天, 也是2月的天數
  2.          '這也是 Excel 判別陽曆y年是否為閏年的另一方法
  3.         Mdays(2) = Day(DateSerial([N1], 3, 1) - 1)
複製代碼
這也是3月1日的前一天
  1. Day(DateSerial([N1], 3, 0))
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 8# yen956
也可以如此
  1. Private Sub EX()
  2.     Dim i As Integer, Rng  As Range, MoDay As Date
  3.     MoDay = DateSerial([n1], [q1], 1)
  4.     With Range("C2:C4")
  5.         .Resize(, 31) = ""
  6.         With .Offset(3).Resize(, 31)
  7.             .UnMerge
  8.             .Rows("2:3") = ""
  9.         End With
  10.         i = 1
  11.        Do While Month(MoDay + i - 1) = Month(MoDay)     '同一月份
  12.             .Cells(1, i) = MoDay + i - 1
  13.             .Cells(2, i) = i
  14.             .Cells(3, i) = Weekday(MoDay + (i - 1), 2)
  15.             .Cells(5, i) = Application.Evaluate("Sum(" & .Cells(4, 1).Resize(, i).Address & ")")
  16.             If .Cells(3, i) = 7 Or i = Day(DateAdd("M", 1, MoDay) - 1) Then '或是 此月份最後一天
  17.                 If i <= 7 Then                                  '第一週
  18.                     Set Rng = .Cells(6, i).Offset(, -(i - 1)).Resize(, i)
  19.                 ElseIf .Cells(3, i) = 7 Then                    '每週
  20.                     Set Rng = .Cells(6, i).Offset(, -6).Resize(, 7)
  21.                 ElseIf i = Day(DateAdd("M", 1, MoDay) - 1) Then  '月底
  22.                     Set Rng = .Cells(6, i).Offset(, -(.Cells(3, i) - 1)).Resize(, .Cells(3, i))
  23.                 End If
  24.                 With Rng
  25.                     .Merge
  26.                     .Cells(1) = Application.Evaluate("Sum(" & .Offset(-2).Cells(1).Resize(, .Columns.Count).Address & ")")
  27.                     .HorizontalAlignment = xlCenter
  28.                     .VerticalAlignment = xlCenter
  29.                     .WrapText = True
  30.                 End With
  31.             End If
  32.             i = i + 1
  33.        Loop
  34.     End With
  35. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 心中常存善解、包容、感思、知足、惜福。
返回列表 上一主題