Comment, please, did I get an adequate algorithm? I believe that it can be improved or at least optimized (
I thought in the direction of regexp, but there was no idea how to screw it in here (
Essence: there are files in the folder at the specified address, you need to find the current one (the number corresponds to the counter of a higher cycle - i). The problem is that before this i can have one more, two or three zeros. And depending on this, different consequences occur)
If (i < 10 And Dir$(folderAdress$ + "TNV - 000" & i & "-1.xls") <> "" And nextsl = True) Then Workbooks.Open folderAdress$ & "TNV - 000" & i & "-1.xls" outTNVfilename = "ТНВ - 000" & i & "-1.xls" tk = "/1" nextsl = False u = i ElseIf (i < 10 And Dir$(folderAdress$ + "TNV - 000" & u & "-2.xls") <> "" And nextsl = False) Then Workbooks.Open folderAdress$ & "TNV - 000" & u & "-2.xls" outTNVfilename = "ТНВ - 000" & u & "-2.xls" tk = "/2" nextsl = True i = u ElseIf (i < 10 And Dir$(folderAdress$ + "TNV - 000" & i & ".xls") <> "") Then Workbooks.Open folderAdress$ & "TNV - 000" & i & ".xls" outTNVfilename = "ТНВ - 000" & i & ".xls" tk = "" ElseIf (i > 9 And i < 100 And Dir$(folderAdress$ + "TNV - 00" & i & "-1.xls") <> "" And nextsl = True) Then Workbooks.Open folderAdress$ & "TNV - 00" & i & "-1.xls" outTNVfilename = "ТНВ - 00" & i & "-1.xls" tk = "/1" nextsl = False u = i ElseIf (i > 9 And i < 100 And Dir$(folderAdress$ + "TNV - 00" & u & "-2.xls") <> "" And nextsl = False) Then Workbooks.Open folderAdress$ & "TNV - 00" & u & "-2.xls" outTNVfilename = "ТНВ - 00" & u & "-2.xls" tk = "/2" nextsl = True i = u ElseIf (i > 9 And i < 100 And Dir$(folderAdress$ + "TNV - 00" & i & ".xls") <> "") Then Workbooks.Open folderAdress$ & "TNV - 00" & i & ".xls" outTNVfilename = "ТНВ - 00" & i & ".xls" tk = "" ElseIf (i > 99 And i < 1000 And Dir$(folderAdress$ + "TNV - 0" & i & "-1.xls") <> "" And nextsl = True) Then Workbooks.Open folderAdress$ & "TNV - 0" & i & "-1.xls" outTNVfilename = "ТНВ - 0" & i & "-1.xls" tk = "/1" nextsl = False u = i ElseIf (i > 99 And i < 1000 And Dir$(folderAdress$ + "TNV - 0" & u & "-2.xls") <> "" And nextsl = False) Then Workbooks.Open folderAdress$ & "TNV - 0" & u & "-2.xls" outTNVfilename = "ТНВ - 0" & u & "-2.xls" tk = "/2" nextsl = True i = u ElseIf (i > 99 And i < 1000 And Dir$(folderAdress$ + "TNV - 0" & i & ".xls") <> "") Then Workbooks.Open folderAdress$ & "TNV - 0" & i & ".xls" outTNVfilename = "ТНВ - 0" & i & ".xls" tk = "" End If