Option Explicit Dim funcs As Functions Dim consts As Constants Dim wbT

  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
Option Explicit
Dim funcs As Functions
Dim consts As Constants
Dim wbThis As Workbook
Dim i As Integer
'вставляем страны в выпадающий список
Public Function insertCountriesInComboBox()
Set funcs = New Functions
Set consts = New Constants
Dim countries As New Dictionary 'создаем ассоциативный массив
Set wbThis = Workbooks(consts.wbThisName())
Dim wsLegals As Worksheet
Set wsLegals = wbThis.Sheets(consts.wsLegalsName()) 'получаем ссылку на лист с организациями
Dim countRows As Integer
countRows = funcs.countRows(wsLegals) 'считаем кол-во строк в этой таблице
For i = 3 To countRows
If Not countries.Exists(wsLegals.Cells(i, 3).Value) Then
countries.Add wsLegals.Cells(i, 3).Value, 1 'добавляем все страны в ассоциативный массив с ключом (название компании) arr[key] = value
'в качестве значения ставим любое значение, в данном случае, мы ставим 1
End If
Next i
Form.countries_comboBox.Clear
For i = 0 To countries.count - 1
Form.countries_comboBox.AddItem countries.Keys(i) 'добавляем страны в выпадающий список
Next i
End Function
'печатаем список компаний с заданными критериями
Public Function printListOfLegals()
Set funcs = New Functions
Set consts = New Constants
Set wbThis = Workbooks(consts.wbThisName())
Dim option_sort As Integer
option_sort = 0 'тип сортировки по количеству сотрудников
If Form.OptionDesc.Value Then
option_sort = 1 'по убыванию
End If
If Form.OptionAsc.Value Then
option_sort = 2 'по возрастанию
End If
Dim selectedCountry As String
selectedCountry = Form.countries_comboBox.Value 'записываем выбранную страну
Dim profitFrom, profitTo As Long
If Trim(Form.fromTextBox.Value) <> "" Then
profitFrom = CLng(Form.fromTextBox.Value) 'записываем сумму в рублях "От"
Else
profitFrom = CLng(-1) * consts.InfinityNum()
End If
If Trim(Form.toTextBox.Value) <> "" Then
profitTo = CLng(Form.toTextBox.Value) 'записываем сумму в рублях "До"
Else
profitTo = consts.InfinityNum()
End If
Dim wsListOfLegals As Worksheet
Set wsListOfLegals = funcs.createWsWithCheck(consts.wsLegalsName() & "2", wbThis)
wsListOfLegals.Tab.ThemeColor = xlThemeColorAccent1
Dim wsOriginalLegals As Worksheet
Set wsOriginalLegals = wbThis.Sheets(consts.wsLegalsName())
wsOriginalLegals.Range(wsOriginalLegals.Cells(1, 1), wsOriginalLegals.Cells(1, 6)).Copy
wsListOfLegals.Cells(1, 1).PasteSpecial
wsOriginalLegals.Range(wsOriginalLegals.Cells(2, 1), wsOriginalLegals.Cells(2, 6)).Copy
wsListOfLegals.Cells(2, 1).PasteSpecial
Dim countRows, Index As Integer
countRows = funcs.countRows(wsOriginalLegals)
Index = 3
For i = 3 To countRows
If wsOriginalLegals.Cells(i, 3) = selectedCountry Or selectedCountry = "" Then
If profitFrom <= wsOriginalLegals.Cells(i, 4) And wsOriginalLegals.Cells(i, 4) <= profitTo Then
wsOriginalLegals.Cells(i, 3).EntireRow.Copy
wsListOfLegals.Cells(Index, 1).PasteSpecial
Index = Index + 1
End If
End If
Next i
funcs.wsAutoFit wsListOfLegals
countRows = funcs.countRows(wsListOfLegals)
If option_sort = 1 Then
wsListOfLegals.Sort.SortFields.Clear
wsListOfLegals.Sort.SortFields.Add Key:=Range(wsListOfLegals.Cells(3, 5), wsListOfLegals.Cells(countRows, 5)), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With wsListOfLegals.Sort
.SetRange Range(wsListOfLegals.Cells(3, 1), wsListOfLegals.Cells(countRows, 6))
.Header = xlNo
.Apply
End With
Else
If option_sort = 2 Then
wsListOfLegals.Sort.SortFields.Clear
wsListOfLegals.Sort.SortFields.Add Key:=Range(wsListOfLegals.Cells(3, 5), wsListOfLegals.Cells(countRows, 5)), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With wsListOfLegals.Sort
.SetRange Range(wsListOfLegals.Cells(3, 1), wsListOfLegals.Cells(countRows, 6))
.Header = xlNo
.Apply
End With
End If
End If
'Печатаем отчет в вордовский документ
funcs.printListInWord wsListOfLegals, consts.wbTemplateLegals1(), "Организации по заданому критерию"
funcs.deleteWithoutAsking wsListOfLegals
End Function
Public Function insertLegalsInComboBox(ByRef comboBox As comboBox)
Set funcs = New Functions
Set consts = New Constants
Dim legals As New Dictionary
Set wbThis = Workbooks(consts.wbThisName())
Dim wsLegals As Worksheet
Set wsLegals = wbThis.Sheets(consts.wsLegalsName())
Dim countRows As Integer
countRows = funcs.countRows(wsLegals)
For i = 3 To countRows
If Not legals.Exists(wsLegals.Cells(i, 2).Value) Then
legals.Add wsLegals.Cells(i, 2).Value, 1
End If
Next i
comboBox.Clear
For i = 0 To legals.count - 1
comboBox.AddItem legals.Keys(i)
Next i
End Function
Public Function printListOfCompanyActivities()
Set funcs = New Functions
Set consts = New Constants
Set wbThis = Workbooks(consts.wbThisName())
Dim wsLegals, wsActivities As Worksheet
Set wsLegals = wbThis.Sheets(consts.wsLegalsName())
Set wsActivities = wbThis.Sheets(consts.wsLegalActivitiesName())
Dim countLegals, countActivities As Integer
countLegals = funcs.countRows(wsLegals)
countActivities = funcs.countRows(wsActivities)
Dim selected_company As String
selected_company = Form.legals_comboBox.Value
If Trim(selected_company) = "" Then
MsgBox "Выберите компанию"
Exit Function
End If
Dim uniq_company_number As Integer
For i = 3 To countLegals
If wsLegals.Cells(i, 2) = selected_company Then
uniq_company_number = CInt(wsLegals.Cells(i, 1))
Exit For
End If
Next i
Dim assocActivities As New Dictionary
Dim wsActivityNames As Worksheet
Set wsActivityNames = wbThis.Sheets(consts.wsActivitiesName())
Dim countActivitiesNames As Integer
countActivitiesNames = funcs.countRows(wsActivityNames)
For i = 3 To countActivitiesNames
assocActivities.Add wsActivityNames.Cells(i, 1).Value, wsActivityNames.Cells(i, 2).Value
Next i
Dim k As Integer
k = 2
Dim wsCompanyActivities As Worksheet
Set wsCompanyActivities = funcs.createWsWithCheck(consts.wsCompanyActivities() & "2", wbThis)
wsCompanyActivities.Tab.ThemeColor = xlThemeColorAccent1
wsCompanyActivities.Cells(1, 1) = "Виды деятельности для комании """ & selected_company & """"
wsCompanyActivities.Cells(1, 1).EntireRow.Interior.ColorIndex = 37
'ищем в листе "Виды деятельности юр. лиц" данную компанию
For i = 3 To countActivities
If wsActivities.Cells(i, 1) = uniq_company_number Then
wsCompanyActivities.Cells(k, 1) = assocActivities.Item(wsActivities.Cells(i, 2).Value)
k = k + 1
End If
Next i
funcs.wsAutoFit wsCompanyActivities
'Печатаем отчет в вордовский документ
funcs.printListInWord wsCompanyActivities, consts.wbTemplateLegals2(), "Список деятельностей для заданной компании"
funcs.deleteWithoutAsking wsCompanyActivities
End Function
Public Function insertActivitiesInComboBox()
Set funcs = New Functions
Set consts = New Constants
Set wbThis = Workbooks(consts.wbThisName())
Dim wsActivities As Worksheet
Set wsActivities = wbThis.Sheets(consts.wsActivitiesName())
Dim countRows As Integer
countRows = funcs.countRows(wsActivities)
Form.listActivities_comboBox.Clear
For i = 3 To countRows
Form.listActivities_comboBox.AddItem wsActivities.Cells(i, 2).Value
Next i
End Function
Public Function printLegalsForActivity()
Set funcs = New Functions
Set consts = New Constants
Dim countries As New Dictionary
Set wbThis = Workbooks(consts.wbThisName())
Dim wsLegals, wsActivities As Worksheet
Set wsLegals = wbThis.Sheets(consts.wsLegalsName())
Set wsActivities = wbThis.Sheets(consts.wsLegalActivitiesName())
Dim countLegals, countActivities As Integer
countLegals = funcs.countRows(wsLegals)
countActivities = funcs.countRows(wsActivities)
Dim selected_activity As String
selected_activity = Form.listActivities_comboBox.Value
If Trim(selected_activity) = "" Then
MsgBox "Выберите деятельность"
Exit Function
End If
Dim assocActivities As New Dictionary
Dim wsActivityNames As Worksheet
Set wsActivityNames = wbThis.Sheets(consts.wsActivitiesName())
Dim countActivitiesNames As Integer
countActivitiesNames = funcs.countRows(wsActivityNames)
For i = 3 To countActivitiesNames
assocActivities.Add wsActivityNames.Cells(i, 2).Value, wsActivityNames.Cells(i, 1).Value
Next i
Dim uniq_activity_number As Integer
uniq_activity_number = assocActivities.Item(selected_activity)
'делаем список компаний с ключом - номер компании
Dim assocLegals As New Dictionary
For i = 3 To countLegals
assocLegals.Add wsLegals.Cells(i, 1).Value, wsLegals.Range(wsLegals.Cells(i, 1), wsLegals.Cells(i, 8))
Next i
'создаем лист для печати списка компаний
Dim wsListOfCompanies As Worksheet
Set wsListOfCompanies = funcs.createWsWithCheck(consts.wsListOfCompaniesForActivity() & "2", wbThis)
wsListOfCompanies.Tab.ThemeColor = xlThemeColorAccent1
wsLegals.Range(wsLegals.Cells(1, 1), wsLegals.Cells(2, 8)).Copy
wsListOfCompanies.Cells(1, 1).PasteSpecial
wsListOfCompanies.Cells(1, 1) = "Список компаний для деятельности """ & selected_activity & """"
'проходим по листу "Виды деятельности юр. лиц" и берем все компании для данной деятельности
Dim k As Integer
k = 3
For i = 3 To countActivities
If wsActivities.Cells(i, 2) = uniq_activity_number Then
assocLegals.Item(wsActivities.Cells(i, 1).Value).Copy
wsListOfCompanies.Cells(k, 1).PasteSpecial
k = k + 1
End If
Next i
funcs.wsAutoFit wsListOfCompanies
'Печатаем отчет в вордовский документ
funcs.printListInWord wsListOfCompanies, consts.wbTemplateLegals3(), "Список организаций для заданной деятельности"
funcs.deleteWithoutAsking wsListOfCompanies
End Function
Public Function printInfoAboutCompany()
Set funcs = New Functions
Set consts = New Constants
Set wbThis = Workbooks(consts.wbThisName())
Dim wsLegals, wsActivities As Worksheet
Set wsLegals = wbThis.Sheets(consts.wsLegalsName())
Set wsActivities = wbThis.Sheets(consts.wsLegalActivitiesName())
Dim countLegals, countActivities As Integer
countLegals = funcs.countRows(wsLegals)
countActivities = funcs.countRows(wsActivities)
Dim wsTaxTypes As Worksheet
Set wsTaxTypes = wbThis.Sheets(consts.taxTypesName())
Dim countTaxTypes As Integer
countTaxTypes = funcs.countRows(wsTaxTypes)
'Создаем ассоциативный массив для видов налога
Dim assocTypes As New Dictionary
For i = 3 To countTaxTypes
assocTypes.Add wsTaxTypes.Cells(i, 1).Value, wsTaxTypes.Cells(i, 2).Value
Next i
'Находим уникальный номер выбранной компании
Dim selected_company As String
selected_company = Form.companies_comboBox.Value
If Trim(selected_company) = "" Then
MsgBox "Выберите компанию"
Exit Function
End If
Dim uniq_company_number As Integer
For i = 3 To countLegals
If wsLegals.Cells(i, 2) = selected_company Then
uniq_company_number = CInt(wsLegals.Cells(i, 1))
Exit For
End If
Next i
'Проходим по списку налогов и ищем выбранную компанию
Dim wsAccountingTax As Worksheet
Set wsAccountingTax = wbThis.Sheets(consts.accountingCompaniesName())
Dim countAccTax As Integer
countAccTax = funcs.countRows(wsAccountingTax)
Dim wsCompanyTaxReport As Worksheet
Set wsCompanyTaxReport = funcs.createWsWithCheck(consts.companyTaxes() & "2", wbThis)
wsCompanyTaxReport.Tab.ThemeColor = xlThemeColorAccent1
wsAccountingTax.Range(wsAccountingTax.Cells(1, 1), wsAccountingTax.Cells(2, 6)).Copy
wsCompanyTaxReport.Cells(1, 1).PasteSpecial
wsCompanyTaxReport.Cells(1, 1) = "Учет налогов для компании: """ & selected_company & """"
wsCompanyTaxReport.Cells(2, 1) = "Организация"
wsCompanyTaxReport.Cells(2, 2) = "Вид налога"
Dim k As Integer
k = 3
For i = 3 To countAccTax
If wsAccountingTax.Cells(i, 1) = uniq_company_number Then
wsAccountingTax.Range(wsAccountingTax.Cells(i, 3), wsAccountingTax.Cells(i, 6)).Copy
wsCompanyTaxReport.Cells(k, 1) = selected_company
wsCompanyTaxReport.Cells(k, 2) = assocTypes.Item(wsAccountingTax.Cells(i, 2).Value)
wsCompanyTaxReport.Cells(k, 3).PasteSpecial
k = k + 1
End If
Next i
funcs.wsAutoFit wsCompanyTaxReport
'Печатаем отчет в вордовский документ
funcs.printListInWord wsCompanyTaxReport, consts.wbTemplateLegals4(), "Налоги для заданной компании"
funcs.deleteWithoutAsking wsCompanyTaxReport
End Function
Public Function insertTaxTypesInComboBox(ByRef comboBox As comboBox)
Set funcs = New Functions
Set consts = New Constants
Set wbThis = Workbooks(consts.wbThisName())
Dim wsTypes As Worksheet
Set wsTypes = wbThis.Sheets(consts.taxTypesName())
Dim countRows As Integer
countRows = funcs.countRows(wsTypes)
comboBox.Clear
For i = 3 To countRows
comboBox.AddItem wsTypes.Cells(i, 2).Value
Next i
End Function
Public Function printTaxesForTaxType()
Set funcs = New Functions
Set consts = New Constants
Set wbThis = Workbooks(consts.wbThisName())
Dim wsLegals, wsActivities As Worksheet
Set wsLegals = wbThis.Sheets(consts.wsLegalsName())
Set wsActivities = wbThis.Sheets(consts.wsLegalActivitiesName())
Dim countLegals, countActivities As Integer
countLegals = funcs.countRows(wsLegals)
countActivities = funcs.countRows(wsActivities)
Dim assocLegals As New Dictionary
For i = 3 To countLegals
assocLegals.Add wsLegals.Cells(i, 1).Value, wsLegals.Cells(i, 2).Value
Next i
Dim wsTaxTypes As Worksheet
Set wsTaxTypes = wbThis.Sheets(consts.taxTypesName())
Dim countTaxTypes As Integer
countTaxTypes = funcs.countRows(wsTaxTypes)
'Создаем ассоциативный массив для видов налога | key = название налога, value = номер налога
Dim assocTypes As New Dictionary
For i = 3 To countTaxTypes
assocTypes.Add wsTaxTypes.Cells(i, 2).Value, wsTaxTypes.Cells(i, 1).Value
Next i
'Находим уникальный номер выбранного налога
Dim selected_tax As String
selected_tax = Form.listOfTaxTypes_comboBox.Value
If Trim(selected_tax) = "" Then
MsgBox "Выберите налог"
Exit Function
End If
Dim uniq_tax_number As Integer
uniq_tax_number = assocTypes.Item(selected_tax)
Dim wsInfoAboutTaxType As Worksheet
Set wsInfoAboutTaxType = funcs.createWsWithCheck(consts.taxesForTaxType() & "2", wbThis)
wsInfoAboutTaxType.Tab.ThemeColor = xlThemeColorAccent1
'Проходим по списку налогов и ищем выбранный налог. Добавляем информацию о налоге на отдельный лист
Dim wsAccountingTax As Worksheet
Set wsAccountingTax = wbThis.Sheets(consts.accountingCompaniesName())
Dim countAccTax As Integer
countAccTax = funcs.countRows(wsAccountingTax)
wsAccountingTax.Range(wsAccountingTax.Cells(1, 1), wsAccountingTax.Cells(2, 6)).Copy
wsInfoAboutTaxType.Cells(1, 1).PasteSpecial
wsInfoAboutTaxType.Cells(1, 1) = "Учет налогов для выбранного типа налога: """ & selected_tax & """"
wsInfoAboutTaxType.Cells(2, 1) = "Организация"
wsInfoAboutTaxType.Range(wsInfoAboutTaxType.Cells(2, 3), wsInfoAboutTaxType.Cells(2, 6)).Copy
wsInfoAboutTaxType.Cells(2, 2).PasteSpecial
wsInfoAboutTaxType.Cells(2, 6).ClearContents
Dim k As Integer
k = 3
For i = 3 To countAccTax
If wsAccountingTax.Cells(i, 2) = uniq_tax_number Then
wsAccountingTax.Range(wsAccountingTax.Cells(i, 3), wsAccountingTax.Cells(i, 6)).Copy
wsInfoAboutTaxType.Cells(k, 2).PasteSpecial
wsInfoAboutTaxType.Cells(k, 1) = assocLegals.Item(wsAccountingTax.Cells(i, 1).Value)
k = k + 1
End If
Next i
funcs.wsAutoFit wsInfoAboutTaxType
'Печатаем отчет в вордовский документ
funcs.printListInWord wsInfoAboutTaxType, consts.wbTemplateLegals5(), "Список налогов для заданного типа налога"
funcs.deleteWithoutAsking wsInfoAboutTaxType
End Function
Public Function printNotPaidCompanies()
Set funcs = New Functions
Set consts = New Constants
Set wbThis = Workbooks(consts.wbThisName())
Dim wsLegals As Worksheet
Set wsLegals = wbThis.Sheets(consts.wsLegalsName())
Dim countLegals As Integer
countLegals = funcs.countRows(wsLegals)
'делаем список компаний с ключом - номер компании
Dim assocLegals As New Dictionary
For i = 3 To countLegals
assocLegals.Add wsLegals.Cells(i, 1).Value, wsLegals.Cells(i, 2).Value
Next i
Dim wsAccountingTax As Worksheet
Set wsAccountingTax = wbThis.Sheets(consts.accountingCompaniesName())
Dim countAccTax As Integer
countAccTax = funcs.countRows(wsAccountingTax)
Dim wsNotPaidCompanies As Worksheet
Set wsNotPaidCompanies = funcs.createWsWithCheck(consts.listOfNotPaidCompanies() & "2", wbThis)
wsNotPaidCompanies.Tab.ThemeColor = xlThemeColorAccent1
wsLegals.Range(wsLegals.Cells(2, 2), wsLegals.Cells(2, 2)).Copy
wsNotPaidCompanies.Cells(1, 1).PasteSpecial
wsAccountingTax.Range(wsAccountingTax.Cells(2, 3), wsAccountingTax.Cells(2, 6)).Copy
wsNotPaidCompanies.Cells(1, 2).PasteSpecial
Dim k As Integer
k = 2
For i = 3 To countAccTax
If wsAccountingTax.Cells(i, 6) > wsAccountingTax.Cells(i, 5) Then
wsNotPaidCompanies.Cells(k, 1) = assocLegals.Item(wsAccountingTax.Cells(i, 1).Value)
wsAccountingTax.Range(wsAccountingTax.Cells(i, 3), wsAccountingTax.Cells(i, 6)).Copy
wsNotPaidCompanies.Cells(k, 2).PasteSpecial
k = k + 1
End If
Next i
funcs.wsAutoFit wsNotPaidCompanies
'Печатаем отчет в вордовский документ
funcs.printListInWord wsNotPaidCompanies, consts.wbTemplateLegals6(), "Не вовремя оплатившие"
funcs.deleteWithoutAsking wsNotPaidCompanies
End Function
Public Function printListOfFailedCheck()
Set funcs = New Functions
Set consts = New Constants
Set wbThis = Workbooks(consts.wbThisName())
Dim wsLegals As Worksheet
Set wsLegals = wbThis.Sheets(consts.wsLegalsName())
Dim countLegals As Integer
countLegals = funcs.countRows(wsLegals)
'делаем список компаний с ключом - номер компании
Dim assocLegals As New Dictionary
For i = 3 To countLegals
assocLegals.Add wsLegals.Cells(i, 1).Value, wsLegals.Cells(i, 2).Value
Next i
Dim wsChecks As Worksheet
Set wsChecks = wbThis.Sheets(consts.checkList())
Dim countChecks As Integer
countChecks = funcs.countRows(wsChecks)
Dim wsFailedChecks As Worksheet
Set wsFailedChecks = funcs.createWsWithCheck(consts.failedChecks() & "2", wbThis)
wsFailedChecks.Tab.ThemeColor = xlThemeColorAccent1
wsChecks.Range(wsChecks.Cells(2, 1), wsChecks.Cells(2, 5)).Copy
wsFailedChecks.Cells(1, 1).PasteSpecial
wsFailedChecks.Cells(1, 1) = "Организация"
Dim k As Integer
k = 2
For i = 3 To countChecks
If Trim(wsChecks.Cells(i, 5)) = "Не удовл." Then
wsChecks.Range(wsChecks.Cells(i, 2), wsChecks.Cells(i, 5)).Copy
wsFailedChecks.Cells(k, 2).PasteSpecial
wsFailedChecks.Cells(k, 1) = assocLegals.Item(wsChecks.Cells(i, 1).Value)
k = k + 1
End If
Next i
funcs.wsAutoFit wsFailedChecks
'Печатаем отчет в вордовский документ
funcs.printListInWord wsFailedChecks, consts.wbTemplateLegals7(), "Не прошедшие проверку компании"
funcs.deleteWithoutAsking wsFailedChecks
End Function
Public Function addTax()
If Trim(Form.add_companies_comboBox.Value) = "" Or Trim(Form.add_taxTypes_comboBox.Value) = "" Or Trim(Form.add_createDate_text.Value) = "" Or _
Trim(Form.add_requireDate_text.Value) = "" Or Trim(Form.add_sum_text.Value) = "" Then
MsgBox "Не все поля заполнены"
Exit Function
End If
Set funcs = New Functions
Set consts = New Constants
Set wbThis = Workbooks(consts.wbThisName())
Dim wsLegals As Worksheet
Set wsLegals = wbThis.Sheets(consts.wsLegalsName())
Dim countLegals As Integer
countLegals = funcs.countRows(wsLegals)
'делаем список компаний с ключом - название компании
Dim assocLegals As New Dictionary
For i = 3 To countLegals
assocLegals.Add wsLegals.Cells(i, 2).Value, wsLegals.Cells(i, 1).Value
Next i
Dim wsTaxTypes As Worksheet
Set wsTaxTypes = wbThis.Sheets(consts.taxTypesName())
Dim countTaxTypes As Integer
countTaxTypes = funcs.countRows(wsTaxTypes)
'Создаем ассоциативный массив для видов налога | key = название налога, value = номер налога
Dim assocTypes As New Dictionary
For i = 3 To countTaxTypes
assocTypes.Add wsTaxTypes.Cells(i, 2).Value, wsTaxTypes.Cells(i, 1).Value
Next i
Dim uniq_company_number, uniq_tax_number As Integer
uniq_company_number = assocLegals.Item(Form.add_companies_comboBox.Value)
uniq_tax_number = assocTypes.Item(Form.add_taxTypes_comboBox.Value)
Dim wsTaxes As Worksheet
Set wsTaxes = wbThis.Sheets(consts.accountingCompaniesName())
Dim countTaxes As Integer
countTaxes = 0
Do While Trim(wsTaxes.Cells(countTaxes + 1, 1).Value) <> ""
countTaxes = countTaxes + 1
Loop
wsTaxes.Cells(countTaxes + 1, 1) = uniq_company_number
wsTaxes.Cells(countTaxes + 1, 2) = uniq_tax_number
wsTaxes.Cells(countTaxes + 1, 3) = Form.add_sum_text.Value
wsTaxes.Cells(countTaxes + 1, 4) = CDate(Form.add_createDate_text.Value)
wsTaxes.Cells(countTaxes + 1, 5) = CDate(Form.add_requireDate_text.Value)
wbThis.Activate
wsTaxes.Select
MsgBox "Налог добавлен"
End Function