|
- Sub text()
- Dim StarTime As Date
- StarTime = Timer
- Dim Wk As Workbook
- Dim aSh As Worksheet, bSh As Worksheet
- Dim Arr, Brr(), xBrr
- Dim x%, y%, i%, j%, N%, R%, C%, aRow%
- Set Wk = ThisWorkbook
- Set aSh = Wk.Sheets("日期自动计算")
- Set bSh = Wk.Sheets("工厂日历")
- aRow = aSh.Cells(Rows.Count, 4).End(xlUp).Row
- Arr = aSh.Range("D1:S" & aRow).Value
- xBrr = bSh.Range("a1").CurrentRegion.Value
- ReDim Brr(1 To UBound(xBrr))
- For x = 2 To UBound(xBrr)
- If xBrr(x, 2) Like "班" Then N = N + 1: Brr(N) = xBrr(x, 1)
- Next x
- For x = 4 To aRow
- If Arr(x, 1) <> "" Then
- For y = 1 To N
- If Arr(x, 1) <= Brr(y) Then
- R = y
- Exit For
- End If
- Next y
- Arr(x, 2) = Brr(R + Arr(1, 2) - 1)
- If Arr(x, 3) <> "" Then Arr(x, 4) = Arr(x, 3) - Arr(x, 2)
- For j = 1 To 4
- C = j * 3 + 2
- If Arr(x, C - 2) <> "" Then
- For y = 1 To N
- If Arr(x, C - 2) <= Brr(y) Then
- R = y
- Exit For
- End If
- Next y
- Arr(x, C) = Brr(R + Arr(1, C))
- If Arr(x, C + 1) <> "" Then Arr(x, C + 2) = Arr(x, C + 1) - Arr(x, C)
- End If
- Next j
- End If
- Next x
- aSh.Range("D1:S" & aRow) = Arr
- MsgBox "OK,用时" & Format(Timer - StarTime, "0.0000") & "秒."
- End Sub
复制代码
我的电脑0.5秒多一点就可以完成了。
但留意日历表要有完整的日期,否则出错。 |
|