|
每周食谱表D2单元格的日期区间更正。- Sub ykcbf() '//2024.7.8 每周食谱(三个条件:每周、星期、餐别)
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim tm: tm = Timer
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- On Error Resume Next
- Set ws = ThisWorkbook
- For Each sht In ws.Sheets
- If InStr(sht.Name, "周") Then sht.Delete
- Next
- p = ws.Path & ""
- Set Sh = ws.Sheets("需求样式")
- bt = 1: col = 2
- With Sheets("每日食谱模拟数据")
- r = .Cells(Rows.Count, col).End(3).Row
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(r, c)
- End With
- For i = bt + 1 To UBound(arr)
- s = arr(i, col) '//每周一表
- ss = "星期" & Weekday(arr(i, 1)) - 1 '//星期提取
- sss = arr(i, 3) '//餐别
- If Not d1.exists(s) Then
- d1(s) = Array(arr(i, 1), arr(i, 1))
- Else
- t = d1(s)
- t(1) = arr(i, 1)
- d1(s) = t
- End If
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- If Not d(s).exists(ss) Then Set d(s)(ss) = CreateObject("Scripting.Dictionary")
- d(s)(ss)(sss) = d(s)(ss)(sss) & Chr(10) & arr(i, 4)
- Next
- For Each k In d.keys
- Sh.Copy After:=ws.Sheets(ws.Sheets.Count)
- Set sht = ws.Sheets(ws.Sheets.Count)
- m = 0
- ReDim brr(1 To 5, 1 To 4)
- rq1 = d1(k)(0): rq2 = d1(k)(1)
- With sht
- For Each kk In d(k).keys
- m = m + 1
- .Name = k
- .[a1] = k & "菜谱"
- .[a4:d8] = ""
- .[d2] = rq1 & "至" & rq2
- brr(m, 1) = kk
- n = 1
- For Each kkk In d(k)(kk).keys
- n = n + 1
- brr(m, n) = Mid(d(k)(kk)(kkk), 2)
- Next
- Next
- .[a4].Resize(m, 4) = brr
- End With
- Next
- Set d = Nothing
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- MsgBox "拆分完毕,共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
|