- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
9#
發表於 2014-4-19 16:24
| 只看該作者
回復 8# yen956
也可以如此- Private Sub EX()
- Dim i As Integer, Rng As Range, MoDay As Date
- MoDay = DateSerial([n1], [q1], 1)
- With Range("C2:C4")
- .Resize(, 31) = ""
- With .Offset(3).Resize(, 31)
- .UnMerge
- .Rows("2:3") = ""
- End With
- i = 1
- Do While Month(MoDay + i - 1) = Month(MoDay) '同一月份
- .Cells(1, i) = MoDay + i - 1
- .Cells(2, i) = i
- .Cells(3, i) = Weekday(MoDay + (i - 1), 2)
- .Cells(5, i) = Application.Evaluate("Sum(" & .Cells(4, 1).Resize(, i).Address & ")")
- If .Cells(3, i) = 7 Or i = Day(DateAdd("M", 1, MoDay) - 1) Then '或是 此月份最後一天
- If i <= 7 Then '第一週
- Set Rng = .Cells(6, i).Offset(, -(i - 1)).Resize(, i)
- ElseIf .Cells(3, i) = 7 Then '每週
- Set Rng = .Cells(6, i).Offset(, -6).Resize(, 7)
- ElseIf i = Day(DateAdd("M", 1, MoDay) - 1) Then '月底
- Set Rng = .Cells(6, i).Offset(, -(.Cells(3, i) - 1)).Resize(, .Cells(3, i))
- End If
- With Rng
- .Merge
- .Cells(1) = Application.Evaluate("Sum(" & .Offset(-2).Cells(1).Resize(, .Columns.Count).Address & ")")
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .WrapText = True
- End With
- End If
- i = i + 1
- Loop
- End With
- End Sub
複製代碼 |
|