Good day!
I have a little issue when copying sheets to another file. I start to copy a first sheet from the file X to a new file Y (see below "ChDir ...", this is working properly. Then I change some selections in the file X and copy the same sheet to the file Y, and so on (see below "Sheets("REP CTY-BRD-MTH").Copy After..."). As I would like the copies being performed one sheet after the other, I am using the variable k which is incremented at the end of the code line ("Sheets(k)). But VBA always stops when trying to copy the second sheet in the new file Y, highlighting the line in yellow with the message "run-time error...". If I put "1" instead of "k", the copies will always be in the same position and not in the following order, but at least it is working.
Any idea why this variable is not accepted ?
Thanks a lot in advance and best regards
-----------------------------------------------------------------------------
Dim k As Integer
...
k = k + 1
ChDir "R:\SGCS\KPI\" & Année & "\Management reports"
ActiveWorkbook.SaveAs Filename:= _
"R:\SGCS\KPI\" & Année & "\Management reports\" & Année & "-" & Mois & "\Brands\KPI_MGT_BRD_" & Right(Année, 2) & "-" & Right(Mois, 2) & "_TCM-NDC-DET.xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
...
Sheets("REP CTY-BRD-MTH").Copy After:=Workbooks("KPI_MGT_BRD_" & Right(Année, 2) & "-" & Right(Mois, 2) & "_TCM-NDC-DET.xlsx").Sheets(k)
-----------------------------------------------------------------------------
I have a little issue when copying sheets to another file. I start to copy a first sheet from the file X to a new file Y (see below "ChDir ...", this is working properly. Then I change some selections in the file X and copy the same sheet to the file Y, and so on (see below "Sheets("REP CTY-BRD-MTH").Copy After..."). As I would like the copies being performed one sheet after the other, I am using the variable k which is incremented at the end of the code line ("Sheets(k)). But VBA always stops when trying to copy the second sheet in the new file Y, highlighting the line in yellow with the message "run-time error...". If I put "1" instead of "k", the copies will always be in the same position and not in the following order, but at least it is working.
Any idea why this variable is not accepted ?
Thanks a lot in advance and best regards
-----------------------------------------------------------------------------
Dim k As Integer
...
k = k + 1
ChDir "R:\SGCS\KPI\" & Année & "\Management reports"
ActiveWorkbook.SaveAs Filename:= _
"R:\SGCS\KPI\" & Année & "\Management reports\" & Année & "-" & Mois & "\Brands\KPI_MGT_BRD_" & Right(Année, 2) & "-" & Right(Mois, 2) & "_TCM-NDC-DET.xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
...
Sheets("REP CTY-BRD-MTH").Copy After:=Workbooks("KPI_MGT_BRD_" & Right(Année, 2) & "-" & Right(Mois, 2) & "_TCM-NDC-DET.xlsx").Sheets(k)
-----------------------------------------------------------------------------