Sub Correction_terms_of_ business_trips For To Worksheets Ñïèñîê öåëåé

  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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
Sub Correction_terms_of_business_trips()
For i = 2 To 9
Worksheets("Ñïèñîê öåëåé").Activate
Dim goal As String
Dim term As Integer
goal = Cells(i, 1)
term = Cells(i, 2)
Worksheets("Êîìàíäèðîâêè").Activate
For j = 2 To 298
If Cells(j, 4) = goal Then
If Cells(j, 3) > term Then
Cells(j, 3) = term
End If
End If
Next j
Next i
End Sub
Sub Correction_of_employees()
Dim i As Integer
i = 3
Worksheets("Êòî åäåò").Activate
Do While Cells(i, 1) <> ""
Dim j As Integer
j = i - 1
Do While j > 2 And Cells(j, 2) <> Cells(i, 2)
j = j - 1
Loop
If Cells(j, 2) = Cells(i, 2) Then
Dim business_trip_first As Long
Dim business_trip_second As Long
business_trip_first = Cells(j, 1)
business_trip_second = Cells(i, 1)
Worksheets("Êîìàíäèðîâêè").Activate
Dim date_of_business_trip_first As Date
Dim date_of_business_trip_second As Date
For k = 2 To 298
If Cells(k, 1) = business_trip_first Then
date_of_business_trip_first = DateAdd("d", Cells(k, 3), Cells(k, 2))
End If
If Cells(k, 1) = business_trip_second Then
date_of_business_trip_second = Cells(k, 2)
End If
Next k
If date_of_business_trip_second <= date_of_business_trip_first Then
Worksheets("Êòî åäåò").Activate
Rows(i).Delete
i = i - 1
End If
End If
i = i + 1
Worksheets("Êòî åäåò").Activate
Loop
End Sub
Public Function Have_an_interpreter(ByRef i, business_trip) As Boolean
Dim is_interpreter As Boolean
is_interpreter = False
Worksheets("Êòî åäåò").Activate
Do While Cells(i, 1) = business_trip
Dim employee As String
employee = Cells(i, 2)
Worksheets("ÇÀÎ ""Ñòðîèòåëü""").Activate
Dim profession As String
For j = 2 To 76
If Cells(j, 1) = employee Then
profession = Cells(j, 4)
Exit For
End If
Next j
Worksheets("ÍÈÈ ""Ðàññâåò""").Activate
For j = 2 To 69
If Cells(j, 1) = employee Then
profession = Cells(j, 4)
Exit For
End If
Next j
If profession = "ïåðåâîä÷èê" Or profession = "ñåêðåòàðü-ïåðåâîä÷èê" Or profession = "àññèñòåíò ïåðåâîä÷èêà" Then
is_interpreter = True
Exit Do
End If
i = i + 1
Worksheets("Êòî åäåò").Activate
Loop
Have_an_interpreter = is_interpreter
End Function
Public Function Free_interpreter(new_business_trip) As String
Dim employee As String
Dim j As Integer
Dim business_trip As Long
Dim ok As Boolean
Dim term_begin As Date
Dim term_end As Date
Dim new_term_begin As Date
Dim new_term_end As Date
For i = 2 To 76
Worksheets("ÇÀÎ ""Ñòðîèòåëü""").Activate
If Cells(i, 4) = "ïåðåâîä÷èê" Or Cells(i, 4) = "ñåêðåòàðü-ïåðåâîä÷èê" Or Cells(i, 4) = "àññèñòåíò ïåðåâîä÷èêà" Then
employee = Cells(i, 1)
j = 2
ok = True
Worksheets("Êòî åäåò").Activate
Do While Cells(j, 1) <> ""
If Cells(j, 2) = employee Then
business_trip = Cells(j, 1)
Worksheets("Êîìàíäèðîâêè").Activate
term_begin = Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 2, 0)
term_end = DateAdd("d", term_begin, Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 3, 0))
new_term_begin = Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 2, 0)
new_term_end = DateAdd("d", new_term_begin, Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 3, 0))
If (term_end >= new_term_begin And term_begin <= new_term_begin) Or (term_end >= new_term_end And term_begin <= new_term_end) Then
ok = False
Exit Do
End If
End If
j = j + 1
Worksheets("Êòî åäåò").Activate
Loop
If ok Then
Free_interpreter = employee
Exit Function
End If
End If
Next i
For i = 2 To 69
Worksheets("ÍÈÈ ""Ðàññâåò""").Activate
If Cells(i, 4) = "ïåðåâîä÷èê" Or Cells(i, 4) = "ñåêðåòàðü-ïåðåâîä÷èê" Or Cells(i, 4) = "àññèñòåíò ïåðåâîä÷èêà" Then
employee = Cells(i, 1)
j = 2
ok = True
Worksheets("Êòî åäåò").Activate
Do While Cells(j, 1) <> ""
If Cells(j, 2) = employee Then
business_trip = Cells(j, 1)
Worksheets("Êîìàíäèðîâêè").Activate
term_begin = Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 2, 0)
term_end = DateAdd("d", term_begin, Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 3, 0))
new_term_begin = Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 2, 0)
new_term_end = DateAdd("d", new_term_begin, Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 3, 0))
If (term_end >= new_term_begin And term_begin <= new_term_begin) Or (term_end >= new_term_end And term_begin <= new_term_end) Then
ok = False
Exit Do
End If
End If
j = j + 1
Worksheets("Êòî åäåò").Activate
Loop
If ok Then
Free_interpreter = employee
Exit Function
End If
End If
Next i
End Function
Public Function Have_an_engineer(ByRef i, business_trip) As Boolean
Dim is_engineer As Boolean
is_engineer = False
Worksheets("Êòî åäåò").Activate
Do While Cells(i, 1) = business_trip
Dim employee As String
employee = Cells(i, 2)
Worksheets("ÇÀÎ ""Ñòðîèòåëü""").Activate
Dim profession As String
For j = 2 To 76
If Cells(j, 1) = employee Then
profession = Cells(j, 4)
Exit For
End If
Next j
Worksheets("ÍÈÈ ""Ðàññâåò""").Activate
For j = 2 To 69
If Cells(j, 1) = employee Then
profession = Cells(j, 4)
Exit For
End If
Next j
If profession = "èíæåíåð" Or profession = "àññèñòåíò èíæåíåðà" Or profession = "ãëàâíûé èíæåíåð" Then
is_engineer = True
Exit Do
End If
i = i + 1
Worksheets("Êòî åäåò").Activate
Loop
Have_an_engineer = is_engineer
End Function
Public Function Free_engineer(new_business_trip) As String
Dim employee As String
Dim j As Integer
Dim business_trip As Long
Dim ok As Boolean
Dim term_begin As Date
Dim term_end As Date
Dim new_term_begin As Date
Dim new_term_end As Date
For i = 2 To 76
Worksheets("ÇÀÎ ""Ñòðîèòåëü""").Activate
If Cells(i, 4) = "èíæåíåð" Or Cells(i, 4) = "àññèñòåíò èíæåíåðà" Or Cells(i, 4) = "ãëàâíûé èíæåíåð" Then
employee = Cells(i, 1)
j = 2
ok = True
Worksheets("Êòî åäåò").Activate
Do While Cells(j, 1) <> ""
If Cells(j, 2) = employee Then
business_trip = Cells(j, 1)
Worksheets("Êîìàíäèðîâêè").Activate
term_begin = Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 2, 0)
term_end = DateAdd("d", term_begin, Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 3, 0))
new_term_begin = Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 2, 0)
new_term_end = DateAdd("d", new_term_begin, Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 3, 0))
If (term_end >= new_term_begin And term_begin <= new_term_begin) Or (term_end >= new_term_end And term_begin <= new_term_end) Then
ok = False
Exit Do
End If
End If
j = j + 1
Worksheets("Êòî åäåò").Activate
Loop
If ok Then
Free_engineer = employee
Exit Function
End If
End If
Next i
For i = 2 To 69
Worksheets("ÍÈÈ ""Ðàññâåò""").Activate
If Cells(i, 4) = "èíæåíåð" Or Cells(i, 4) = "àññèñòåíò èíæåíåðà" Or Cells(i, 4) = "ãëàâíûé èíæåíåð" Then
employee = Cells(i, 1)
j = 2
ok = True
Worksheets("Êòî åäåò").Activate
Do While Cells(j, 1) <> ""
If Cells(j, 2) = employee Then
business_trip = Cells(j, 1)
Worksheets("Êîìàíäèðîâêè").Activate
term_begin = Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 2, 0)
term_end = DateAdd("d", term_begin, Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 3, 0))
new_term_begin = Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 2, 0)
new_term_end = DateAdd("d", new_term_begin, Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 3, 0))
If (term_end >= new_term_begin And term_begin <= new_term_begin) Or (term_end >= new_term_end And term_begin <= new_term_end) Then
ok = False
Exit Do
End If
End If
j = j + 1
Worksheets("Êòî åäåò").Activate
Loop
If ok Then
Free_engineer = employee
Exit Function
End If
End If
Next i
End Function
Public Function Have_an_technologist_or_builder(ByRef i, business_trip) As Boolean
Dim is_technologist_or_builder As Boolean
is_technologist_or_builder = False
Worksheets("Êòî åäåò").Activate
Do While Cells(i, 1) = business_trip
Dim employee As String
employee = Cells(i, 2)
Worksheets("ÇÀÎ ""Ñòðîèòåëü""").Activate
Dim profession As String
For j = 2 To 76
If Cells(j, 1) = employee Then
profession = Cells(j, 4)
Exit For
End If
Next j
Worksheets("ÍÈÈ ""Ðàññâåò""").Activate
For j = 2 To 69
If Cells(j, 1) = employee Then
profession = Cells(j, 4)
Exit For
End If
Next j
If profession = "òåõíîëîã" Or profession = "ñòðîèòåëü" Then
is_technologist_or_builder = True
Exit Do
End If
i = i + 1
Worksheets("Êòî åäåò").Activate
Loop
Have_an_technologist_or_builder = is_technologist_or_builder
End Function
Public Function Free_technologist_or_builder(new_business_trip) As String
Dim employee As String
Dim j As Integer
Dim business_trip As Long
Dim ok As Boolean
Dim term_begin As Date
Dim term_end As Date
Dim new_term_begin As Date
Dim new_term_end As Date
For i = 2 To 76
Worksheets("ÇÀÎ ""Ñòðîèòåëü""").Activate
If Cells(i, 4) = "òåõíîëîã" Or Cells(i, 4) = "ñòðîèòåëü" Then
employee = Cells(i, 1)
j = 2
ok = True
Worksheets("Êòî åäåò").Activate
Do While Cells(j, 1) <> ""
If Cells(j, 2) = employee Then
business_trip = Cells(j, 1)
Worksheets("Êîìàíäèðîâêè").Activate
term_begin = Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 2, 0)
term_end = DateAdd("d", term_begin, Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 3, 0))
new_term_begin = Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 2, 0)
new_term_end = DateAdd("d", new_term_begin, Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 3, 0))
If (term_end >= new_term_begin And term_begin <= new_term_begin) Or (term_end >= new_term_end And term_begin <= new_term_end) Then
ok = False
Exit Do
End If
End If
j = j + 1
Worksheets("Êòî åäåò").Activate
Loop
If ok Then
Free_technologist_or_builder = employee
Exit Function
End If
End If
Next i
For i = 2 To 69
Worksheets("ÍÈÈ ""Ðàññâåò""").Activate
If Cells(i, 4) = "òåõíîëîã" Or Cells(i, 4) = "ñòðîèòåëü" Then
employee = Cells(i, 1)
j = 2
ok = True
Worksheets("Êòî åäåò").Activate
Do While Cells(j, 1) <> ""
If Cells(j, 2) = employee Then
business_trip = Cells(j, 1)
Worksheets("Êîìàíäèðîâêè").Activate
term_begin = Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 2, 0)
term_end = DateAdd("d", term_begin, Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 3, 0))
new_term_begin = Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 2, 0)
new_term_end = DateAdd("d", new_term_begin, Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 3, 0))
If (term_end >= new_term_begin And term_begin <= new_term_begin) Or (term_end >= new_term_end And term_begin <= new_term_end) Then
ok = False
Exit Do
End If
End If
j = j + 1
Worksheets("Êòî åäåò").Activate
Loop
If ok Then
Free_technologist_or_builder = employee
Exit Function
End If
End If
Next i
End Function
Public Function Have_an_builder_or_sectione_chief_or_foreman(ByRef i, business_trip) As Boolean
Dim is_builder_or_sectione_chief_or_foreman As Boolean
is_builder_or_sectione_chief_or_foreman = False
Worksheets("Êòî åäåò").Activate
Do While Cells(i, 1) = business_trip
Dim employee As String
employee = Cells(i, 2)
Worksheets("ÇÀÎ ""Ñòðîèòåëü""").Activate
Dim profession As String
For j = 2 To 76
If Cells(j, 1) = employee Then
profession = Cells(j, 4)
Exit For
End If
Next j
Worksheets("ÍÈÈ ""Ðàññâåò""").Activate
For j = 2 To 69
If Cells(j, 1) = employee Then
profession = Cells(j, 4)
Exit For
End If
Next j
If profession = "ñòðîèòåëü" Or profession = "íà÷àëüíèê ó÷àñòêà" Or profession = "ïðîðàá" Then
is_builder_or_sectione_chief_or_foreman = True
Exit Do
End If
i = i + 1
Worksheets("Êòî åäåò").Activate
Loop
Have_an_builder_or_sectione_chief_or_foreman = is_builder_or_sectione_chief_or_foreman
End Function
Public Function Free_builder_or_sectione_chief_or_foreman(new_business_trip) As String
Dim employee As String
Dim j As Integer
Dim business_trip As Long
Dim ok As Boolean
Dim term_begin As Date
Dim term_end As Date
Dim new_term_begin As Date
Dim new_term_end As Date
For i = 2 To 76
Worksheets("ÇÀÎ ""Ñòðîèòåëü""").Activate
If Cells(i, 4) = "ñòðîèòåëü" Or Cells(i, 4) = "íà÷àëüíèê ó÷àñòêà" Or Cells(i, 4) = "ïðîðàá" Then
employee = Cells(i, 1)
j = 2
ok = True
Worksheets("Êòî åäåò").Activate
Do While Cells(j, 1) <> ""
If Cells(j, 2) = employee Then
business_trip = Cells(j, 1)
Worksheets("Êîìàíäèðîâêè").Activate
term_begin = Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 2, 0)
term_end = DateAdd("d", term_begin, Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 3, 0))
new_term_begin = Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 2, 0)
new_term_end = DateAdd("d", new_term_begin, Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 3, 0))
If (term_end >= new_term_begin And term_begin <= new_term_begin) Or (term_end >= new_term_end And term_begin <= new_term_end) Then
ok = False
Exit Do
End If
End If
j = j + 1
Worksheets("Êòî åäåò").Activate
Loop
If ok Then
Free_builder_or_sectione_chief_or_foreman = employee
Exit Function
End If
End If
Next i
For i = 2 To 69
Worksheets("ÍÈÈ ""Ðàññâåò""").Activate
If Cells(i, 4) = "ñòðîèòåëü" Or Cells(i, 4) = "íà÷àëüíèê ó÷àñòêà" Or Cells(i, 4) = "ïðîðàá" Then
employee = Cells(i, 1)
j = 2
ok = True
Worksheets("Êòî åäåò").Activate
Do While Cells(j, 1) <> ""
If Cells(j, 2) = employee Then
business_trip = Cells(j, 1)
Worksheets("Êîìàíäèðîâêè").Activate
term_begin = Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 2, 0)
term_end = DateAdd("d", term_begin, Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 3, 0))
new_term_begin = Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 2, 0)
new_term_end = DateAdd("d", new_term_begin, Application.WorksheetFunction.VLookup(new_business_trip, Range("A2:C298"), 3, 0))
If (term_end >= new_term_begin And term_begin <= new_term_begin) Or (term_end >= new_term_end And term_begin <= new_term_end) Then
ok = False
Exit Do
End If
End If
j = j + 1
Worksheets("Êòî åäåò").Activate
Loop
If ok Then
Free_builder_or_sectione_chief_or_foreman = employee
Exit Function
End If
End If
Next i
End Function
Sub Analysis_of_employees()
Dim i As Integer
i = 2
Dim id_business_trip As Integer
Dim business_trip As Long
Dim employee As String
id_business_trip = 1
Worksheets("Êòî åäåò").Activate
Do While Cells(i, 1) <> ""
business_trip = Cells(i, 1)
If business_trip <> Cells(i - 1, 1) Then
id_business_trip = id_business_trip + 1
End If
Worksheets("Êîìàíäèðîâêè").Activate
Dim destination As String
destination = Cells(id_business_trip, 5)
For j = 1 To 27
Worksheets("Ñïèñîê ãîðîäîâ âíå").Activate
If destination = Cells(j, 1) Then
If Not Have_an_interpreter(i, business_trip) Then
employee = Free_interpreter(business_trip)
Worksheets("Êòî åäåò").Activate
Rows(i).Select
Selection.Insert Shift:=xlDown
Cells(i, 1) = business_trip
Cells(i, 2) = employee
Else
Worksheets("Êòî åäåò").Activate
Do While business_trip = Cells(i + 1, 1)
i = i + 1
Loop
End If
Exit For
End If
Next j
i = i + 1
Worksheets("Êòî åäåò").Activate
Loop
i = 2
id_business_trip = 1
Worksheets("Êòî åäåò").Activate
Do While Cells(i, 1) <> ""
business_trip = Cells(i, 1)
If business_trip <> Cells(i - 1, 1) Then
id_business_trip = id_business_trip + 1
End If
Worksheets("Êîìàíäèðîâêè").Activate
Dim goal As String
If business_trip <> Cells(id_business_trip, 1) Then
id_business_trip = id_business_trip + 1
End If
goal = Cells(id_business_trip, 4)
If goal = "Èñïûòàíèÿ" Then
If Not Have_an_engineer(i, business_trip) Then
employee = Free_engineer(business_trip)
Worksheets("Êòî åäåò").Activate
Rows(i).Select
Selection.Insert Shift:=xlDown
Cells(i, 1) = business_trip
Cells(i, 2) = employee
Else
Worksheets("Êòî åäåò").Activate
Do While business_trip = Cells(i + 1, 1)
i = i + 1
Loop
End If
End If
If goal = "Ïðåäâàðèòåëüíîå îáñëåäîâàíèå" Then
If Not Have_an_technologist_or_builder(i, business_trip) Then
employee = Free_technologist_or_builder(business_trip)
Worksheets("Êòî åäåò").Activate
Rows(i).Select
Selection.Insert Shift:=xlDown
Cells(i, 1) = business_trip
Cells(i, 2) = employee
Else
Worksheets("Êòî åäåò").Activate
Do While business_trip = Cells(i + 1, 1)
i = i + 1
Loop
End If
End If
If goal = "Ñòðîèòåëüñòâî" Then
If Not Have_an_builder_or_sectione_chief_or_foreman(i, business_trip) Then
employee = Free_builder_or_sectione_chief_or_foreman(business_trip)
Worksheets("Êòî åäåò").Activate
Rows(i).Select
Selection.Insert Shift:=xlDown
Cells(i, 1) = business_trip
Cells(i, 2) = employee
Else
Worksheets("Êòî åäåò").Activate
Do While business_trip = Cells(i + 1, 1)
i = i + 1
Loop
End If
End If
Do While business_trip = Cells(i + 1, 1)
i = i + 1
Loop
i = i + 1
Worksheets("Êòî åäåò").Activate
Loop
End Sub
Sub Plan_of_business_trip()
Sheets.Add After:=Sheets(Sheets.count)
Sheets(Sheets.count).Select
Sheets(Sheets.count).Name = "Ïëàí êîìàíäèðîâîê"
Dim enployee As String
Dim j As Integer
Dim business_trip As Long
Dim count As Integer
Worksheets("ÇÀÎ ""Ñòðîèòåëü""").Activate
For i = 2 To 76
employee = Cells(i, 1)
Worksheets("Ïëàí êîìàíäèðîâîê").Activate
Cells(i - 1, 1) = employee
Worksheets("Êòî åäåò").Activate
count = 2
j = 2
Do While Cells(j, 1) <> ""
If Cells(j, 2) = employee Then
business_trip = Cells(j, 1)
Worksheets("Ïëàí êîìàíäèðîâîê").Activate
Cells(i - 1, count) = business_trip
count = count + 1
End If
j = j + 1
Worksheets("Êòî åäåò").Activate
Loop
Worksheets("ÇÀÎ ""Ñòðîèòåëü""").Activate
Next i
Worksheets("ÍÈÈ ""Ðàññâåò""").Activate
For i = 2 To 69
employee = Cells(i, 1)
Worksheets("Ïëàí êîìàíäèðîâîê").Activate
Cells(i + 74, 1) = employee
Worksheets("Êòî åäåò").Activate
count = 2
j = 2
Do While Cells(j, 1) <> ""
If Cells(j, 2) = employee Then
business_trip = Cells(j, 1)
Worksheets("Ïëàí êîìàíäèðîâîê").Activate
Cells(i + 74, count) = business_trip
count = count + 1
End If
j = j + 1
Worksheets("Êòî åäåò").Activate
Loop
Worksheets("ÍÈÈ ""Ðàññâåò""").Activate
Next i
End Sub
Sub Lowly_involved()
Sheets.Add After:=Sheets(Sheets.count)
Sheets(Sheets.count).Select
Sheets(Sheets.count).Name = "Ìàëî çàäåéñòâîâàíû"
Dim count As Integer
Dim i As Integer
Dim employee As String
Dim id As Integer
id = 1
i = 1
Worksheets("Ïëàí êîìàíäèðîâîê").Activate
Do While Cells(i, 1) <> ""
count = 0
employee = Cells(i, 1)
Do While Cells(i, count + 2) <> ""
count = count + 1
Loop
If count <= 5 Then
Worksheets("Ìàëî çàäåéñòâîâàíû").Activate
Cells(id, 1) = employee
id = id + 1
End If
i = i + 1
Worksheets("Ïëàí êîìàíäèðîâîê").Activate
Loop
End Sub
Sub Cost_of_business_trip()
Sheets.Add After:=Sheets(Sheets.count)
Sheets(Sheets.count).Select
Sheets(Sheets.count).Name = "Ñòîèìîñòü êîìàíäèðîâîê"
Dim count As Integer
Dim i As Integer
Dim business_trip As Long
Dim destination As String
Dim term As Long
Dim cost As Long
Dim id As Integer
Dim real_cost As Long
id = 1
i = 2
count = 1
Worksheets("Êòî åäåò").Activate
Do While Cells(i, 1) <> ""
business_trip = Cells(i, 1)
count = 1
Do While Cells(i, 1) = Cells(i + 1, 1)
i = i + 1
count = count + 1
Loop
Worksheets("Êîìàíäèðîâêè").Activate
destination = Application.WorksheetFunction.VLookup(business_trip, Range("A2:E298"), 5, 0)
destination = Mid(destination, InStr(destination, "(") + 1, Len(destination) - InStr(destination, "(") - 1)
term = Application.WorksheetFunction.VLookup(business_trip, Range("A2:C298"), 3, 0)
Worksheets("Ñïèñîê îáëàñòåé").Activate
For j = 2 To 55
If destination = Cells(j, 1) Then
If Cells(j, 2) = "" Then
cost = 1500 * term * count
Else
cost = Cells(j, 2) * term * count
End If
cost = cost + Cells(j, 3) * count * 2
End If
Next j
Worksheets("Ñïèñîê ñòðàí").Activate
For j = 2 To 12
If destination = Cells(j, 1) Then
cost = Cells(j, 2) * term * count
cost = cost + Cells(j, 3) * count * 2
End If
Next j
Worksheets("Ñòîèìîñòü êîìàíäèðîâîê").Activate
Cells(id, 1) = business_trip
Cells(id, 2) = cost
id = id + 1
i = i + 1
Worksheets("Êòî åäåò").Activate
Loop
Worksheets("Êîìàíäèðîâêè").Activate
For j = 2 To 298
Cells(j, 8) = Cells(j, 6)
Next j
For j = 2 To 298
business_trip = Cells(j, 1)
cost = Cells(j, 8)
If cost <> 0 Then
Worksheets("Ñòîèìîñòü êîìàíäèðîâîê").Activate
For k = 1 To 295
If Cells(k, 1) = business_trip Then
Cells(k, 3) = cost - Cells(k, 2)
Exit For
End If
Next k
Else
Worksheets("Ñòîèìîñòü êîìàíäèðîâîê").Activate
For k = 1 To 295
If Cells(k, 1) = business_trip Then
Cells(k, 3) = Cells(k, 2)
real_cost = Cells(k, 2)
Exit For
End If
Next k
Worksheets("Êîìàíäèðîâêè").Activate
Dim test As Integer
Cells(Application.WorksheetFunction.Match(Cells(j, 7), Range("A1:A298"), 0), 8) = Cells(Application.WorksheetFunction.Match(Cells(j, 7), Range("A1:A298"), 0), 8) - real_cost
End If
Worksheets("Êîìàíäèðîâêè").Activate
Next j
Worksheets("Êîìàíäèðîâêè").Activate
For j = 2 To 298
Cells(j, 8) = ""
Next j
Sheets.Add After:=Sheets(Sheets.count)
Sheets(Sheets.count).Select
Sheets(Sheets.count).Name = "Íåðåíòàáåëüíûå êîìàíäèðîâêè"
Worksheets("Ñòîèìîñòü êîìàíäèðîâîê").Activate
id = 1
For j = 1 To 295
If Cells(j, 3) < 0 Then
business_trip = Cells(j, 1)
Worksheets("Íåðåíòàáåëüíûå êîìàíäèðîâêè").Activate
Cells(id, 1) = business_trip
id = id + 1
End If
Worksheets("Ñòîèìîñòü êîìàíäèðîâîê").Activate
Next j
End Sub