Sub Task4 Declare const Const quote As String Declare sheets Set Tripe

 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Sub Task4()
' Declare const ""
Const quote As String = """"
' Declare sheets
Set Tripers = Worksheets.Add
Tripers.Name = "Командированные"
Set Trips = Worksheets("Кто едет")
Set Dates = Worksheets("Командировки")
Dim Emploees_Array As New Dictionary
' Declare array of company
Dim Company_Array(2) As String
Dim Trips_Array() As String
' Add name of company in array
Company_Array(0) = "НИИ " & quote & "Рассвет" & quote
Company_Array(1) = "ЗАО " & quote & "Строитель" & quote
Company_Array(2) = "Приглашенные сотрудники"
For Each test In Company_Array
For i = 2 To Worksheets(test).Cells(2, 1).CurrentRegion.Rows.Count
Emploees_Array.Add Worksheets(test).Cells(i, 1).Value, Worksheets(test).Cells(i, 1)
Next
Next
' Remove dublicates to Trips sheets
nCol_Trip = Trips.Cells(1, 1).CurrentRegion.Columns.Count
nRow_Trip = Trips.Cells(1, 1).CurrentRegion.Rows.Count
Trips.Range(Trips.Cells(1, 1), Trips.Cells(nRow_Trip, nCol_Trip)).RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
For Each Worker In Emploees_Array
Enter = 0
For i = 2 To nRow_Trip
If Worker = Trips.Cells(i, 2) Then
Enter = Enter + 1
End If
Next
ReDim Trips_Array(Enter)
Key = 0
For i = 2 To nRow_Trip
If Worker = Trips.Cells(i, 2) Then
Trips_Array(Key) = Trips.Cells(i, 1)
Key = Key + 1
End If
Next
Emploees_Array.Item(Worker) = Trips_Array
Next
Tripers.Cells(1, 2).ColumnWidth = 20
Enter1 = 2
Tripers.Cells(Enter1, 1).EntireRow.Borders(xlEdgeTop).Weight = xlThick
For Each Worker In Emploees_Array
'Tripers.Cells(Enter1, 1) = Worker
For Each Number In Emploees_Array.Item(Worker)
If Number <> "" Then
Tripers.Cells(Enter1, 2) = Worker
Tripers.Cells(Enter1, 1) = Number
Enter1 = Enter1 + 1
End If
Next
' Color border bottom
Tripers.Cells(Enter1, 1).EntireRow.Borders(xlEdgeTop).Weight = xlThick
Next
End Sub