- Sub tt()
- Dim ar, br, cr, i%, t, s, d, df, n%
- ar = [a1].CurrentRegion
- Set br = [i1].CurrentRegion
- Set cr = [o2:o6]
- For i = 2 To UBound(ar)
- Set t = br.Find(ar(i, 1))
- If Not t Is Nothing And ar(i, 1) <> "" Then
- If InStr("头领|上级", Cells(1, t.Column)) > 0 Then
- ar(i, 4) = ar(i, 1)
- ar(i, 5) = ar(i, 1)
- ar(i, 6) = Cells(t.Row, 9)
- Else
- ar(i, 4) = Cells(t.Row, t.Column - 1)
- ar(i, 5) = Cells(t.Row, t.Column - 2)
- ar(i, 6) = Cells(t.Row, t.Column - 3)
- End If
- End If
- Set s = cr.Find(ar(i, 1))
- If Not s Is Nothing And ar(i, 1) <> "" Then
- d = s.Offset(0, 1).Value '变更表的日期
- df = DateDiff("d", ar(i, 3), d) '与变更表日期的相隔天数
- If ar(i, 1) = "吕布" Then
- n = 3
- Do While DateDiff("d", ar(i, 3), Cells(n, "p")) >= 0
- ar(i, 4) = Cells(n, "p").Offset(0, 1)
- ar(i, 5) = Cells(n, "p").Offset(0, 2)
- ar(i, 6) = Cells(n, "p").Offset(0, 3)
- n = n - 1
- If n < 2 Then Exit Do
- Loop
- ElseIf df >= 0 Then
- ar(i, 4) = Cells(s.Row, "p").Offset(0, 1)
- ar(i, 5) = Cells(s.Row, "p").Offset(0, 2)
- ar(i, 6) = Cells(s.Row, "p").Offset(0, 3)
- End If
- End If
- Set s = Nothing
- Set t = Nothing
- Next i
- [a1].Resize(UBound(ar), 6) = ar
- Set br = Nothing
- Set cr = Nothing
- End Sub
复制代码 |