Sub Тест_3 Set Sheets Командировки Set Sheets Кто едет Dim row As Inte

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Sub Тест_3()
Set a = Sheets("Командировки")
Set b = Sheets("Кто едет")
Dim n, m, row, e As Integer
Dim d1, d2, d3, d4 As Date
e = 1656
row = 3
For i = 2 To e - 1
For l = i + 1 To e
If b.Cells(i, 2).Value = b.Cells(l, 2).Value Then
n = b.Cells(i, 1).Value
m = b.Cells(l, 1).Value
a.Select
For j = 2 To 298
If n = a.Cells(j, 1) Then
d1 = a.Cells(j, 2)
d3 = DateAdd("d", a.Cells(j, 3).Value, d1)
End If
If m = a.Cells(j, 1).Value Then
d2 = a.Cells(j, 2).Value
d4 = DateAdd("d", a.Cells(j, 3).Value, d2)
End If
Next j
b.Cells(1, 5).Value = "Списки исключенных"
b.Cells(2, 5).Value = "Номер командировки"
b.Cells(2, 6).Value = "Фамилия"
If d3 >= d2 Then
b.Cells(row, 5) = b.Cells(i, 1).Value
b.Cells(row, 6) = b.Cells(i, 2).Value
b.Cells(i, 1).Delete
b.Cells(i, 2).Delete
row = row + 1
e = e - 1
End If
End If
Next l
Next i
End Sub