row_abc_end = abc.Cells(Rows.Count, 1).End(xlUp).Row
row_dist_end = district.Cells(Rows.Count, 1).End(xlUp).Row
part_of_path = ThisWorkbook.Path
For row_port = 2 To row_port_end
If portion.Cells(row_port, 9) <> "обработано" Then
index = Left(portion.Cells(row_port, 7), 6)
For row_dist = 2 To row_dist_end
If index >= district.Cells(row_dist, 3) And index <= district.Cells(row_dist, 4) And district.Cells(row_dist, 5) = "Да" Then
portion.Cells(row_port, 9) = "обработано"
archive.Cells(row_arc, 1) = portion.Cells(row_port, 1)
archive.Cells(row_arc, 2) = portion.Cells(row_port, 2)
archive.Cells(row_arc, 3) = portion.Cells(row_port, 8)
archive.Cells(row_arc, 4) = portion.Cells(row_port, 6)
archive.Cells(row_arc, 8) = Str(Date)
archive.Cells(row_arc, 9) = "1"
'здесь код не работает
For row_abc = 2 To row_abc_end
If abc.Cells(row_abc, 1) = district.Cells(row_dist, 6) Then
archive.Cells(row_arc, 10) = abc.Cells(row_abc, 2)
archive.Cells(row_arc, 11) = abc.Cells(row_abc, 4)
archive.Cells(row_arc, 12) = abc.Cells(row_abc, 5)
archive.Cells(row_arc, 13) = abc.Cells(row_abc, 6)
archive.Cells(row_arc, 14) = abc.Cells(row_abc, 7)
archive.Cells(row_arc, 15) = abc.Cells(row_abc, 8)
archive.Cells(row_arc, 16) = abc.Cells(row_abc, 9)
archive.Cells(row_arc, 17) = Str(abc.Cells(row_abc, 13)) & ", " _
& abc.Cells(row_abc, 12)
Exit For
End If
Next row_abc
'здесь снова работает
'но далее на месте abc.Cells(row_abc, 2) пусто
If Dir(part_of_path & "\" & abc.Cells(row_abc, 2) & " " & Date & ".xlsx") = "" Then
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=part_of_path & "\" & abc.Cells(row_abc, 2) & " " & Date & ".xlsx"
Call file_formatting
ActiveWorkbook.Close SaveChanges:=True
End If
Set output_data = Workbooks.Open(Filename:=part_of_path & "\" & abc.Cells(row_abc, 2) & " " & Date & ".xlsx").Sheets(1)
row_out = output_data.Cells(Rows.Count, 1).End(xlUp).Row + 1
output_data.Cells(row_out, 1) = archive.Cells(row_arc, 1)
output_data.Cells(row_out, 2) = archive.Cells(row_arc, 2)
output_data.Cells(row_out, 3) = archive.Cells(row_arc, 3)
output_data.Cells(row_out, 4) = archive.Cells(row_arc, 4)
ActiveWorkbook.Close SaveChanges:=True
row_arc = row_arc + 1
End If
Next row_dist
End If
Next row_port