Re : Copier une feuille contenant une marco d'un classeur à un autre
Je ne peux t'envoyer le fichier car il est trop volumineux par contre je te met le détail de la macro si cela peut t'éclaircir :
Sub importerspread()
Dim NomFichier As String
Dim NomFichier1 As String
Dim NomFichier2 As String
NomFichier = InputBox("Veuillez saisir le nom du fichier d'où vont être importés les paramètres crédits du mois en cours" & vbCr & "Par exemple: Barèmes_RAC_Mai_2009_TRC.xls")
GetData "S:\DCG\DCG_Commun\CNCE-Rac\Barèmes\2009\" & NomFichier, "BAREMES", _
"B5:J17333", Sheets("Traitement").Range("A1"), True, False
On Error GoTo Fin
If NomFichier = "" Then
GoTo Fin
End If
Dim ProfilRA As String
Dim periodicite As String
Dim Typeamortissement As String
ProfilRA = InputBox("Veuillez choisir un profil RA pour les crédits à taux révisable: 0, 3, 5 ou 10")
periodicite = InputBox("Veuillez choisir la périodicité de remboursement pour les crédits à taux révisable" & vbCr & " M pour mensuel" & vbCr & "T pour trimestriel" & vbCr & " S pour semestriel" & vbCr & " A pour annuel")
Typeamortissement = InputBox("Veuillez choisir le type d'amortissement pour les crédits à taux révisable" & vbCr & " P pour échéance constante" & vbCr & "C pour part capital constante" & vbCr & " I pour infine")
If ProfilRA <> "0" And ProfilRA <> "3" And ProfilRA <> "5" And ProfilRA <> "10" Then
MsgBox ("Erreur de saisie ou sélection inexistante")
GoTo Fin
ElseIf periodicite <> "M" And periodicité <> "T" And periodicite <> "S" And periodicite <> "A" Then
MsgBox ("Erreur de saisie ou sélection inexistante")
GoTo Fin
ElseIf Typeamortissement <> "P" And Typeamortissement <> "C" And Typeamortissement <> "I" Then
MsgBox ("Erreur de saisie ou sélection inexistante")
GoTo Fin
Else
Worksheets("TCI crédit").Select
Range("B3").Select
ActiveCell.FormulaR1C1 = ProfilRA
Range("B4").Select
ActiveCell.FormulaR1C1 = periodicite
Range("B5").Select
ActiveCell.FormulaR1C1 = Typeamortissement
Worksheets("Traitement").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "a"
Range("B1").Select
ActiveCell.FormulaR1C1 = "b"
Range("C1").Select
ActiveCell.FormulaR1C1 = "c"
Range("D1").Select
ActiveCell.FormulaR1C1 = "swap"
Range("E1").Select
ActiveCell.FormulaR1C1 = "spread haut"
Range("F1").Select
ActiveCell.FormulaR1C1 = "spread bas"
Range("G1").Select
ActiveCell.FormulaR1C1 = "TAN haut"
Range("H1").Select
ActiveCell.FormulaR1C1 = "Tan bas"
Range("I1").Select
ActiveCell.FormulaR1C1 = "DVMA"
Range("A1:I17428").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=ProfilRA
Selection.AutoFilter Field:=2, Criteria1:=periodicite
Selection.AutoFilter Field:=3, Criteria1:=Typeamortissement
'pour spread E1:E18369
'pour TAN G
'pour dvma I
Columns("D😀").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("AI1").Select
ActiveSheet.Paste
Worksheets("Traitement").Select
Columns("E:E").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("H1").Select
ActiveSheet.Paste
For i = 1 To 349 Step 12
Range("J" & i).Select
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-2]:R[11]C[-2])/100"
Next i
Range("J1:J360").Select
Selection.NumberFormat = "0.00%"
Selection.SpecialCells(xlCellTypeFormulas, 23).Select
Selection.Copy
Range("M2").Select
ActiveSheet.Paste
Range("M1").Select
Application.CutCopyMode = False
MsgBox ("Données crédits taux révisable importées avec succès")
End If
Worksheets("Traitement").Select
'Dim ProfilRA1 As String
'Dim periodicite1 As String
'Dim Typeamortissement1 As String
'ProfilRA1 = InputBox("Veuillez choisir un profil RA pour les crédits taux fixe : 0, 3, 5 ou 10")
'periodicite1 = InputBox("Veuillez choisir la périodicité de remboursement pour les crédits taux fixe" & vbCr & " M pour mensuel" & vbCr & "T pour trimestriel" & vbCr & " S pour semestriel" & vbCr & " A pour annuel")
'Typeamortissement1 = InputBox("Veuillez choisir le type d'amortissement pour les crédits taux fixe" & vbCr & " P pour échéance constante" & vbCr & "C pour part capital constante" & vbCr & " I pour infine")
'If ProfilRA1 <> "0" And ProfilRA1 <> "3" And ProfilRA1 <> "5" And ProfilRA1 <> "10" Then
'MsgBox ("Erreur de saisie")
'GoTo Fin
'ElseIf periodicite1 <> "M" And periodicite1 <> "T" And periodicite1 <> "S" And periodicite1 <> "A" Then
'MsgBox ("Erreur de saisie")
'GoTo Fin
'ElseIf Typeamortissement1 <> "P" And Typeamortissement1 <> "C" And Typeamortissement1 <> "I" Then
'MsgBox ("Erreur de saisie")
'GoTo Fin
'Else
'Range("A1:I17428").Select
'Selection.AutoFilter
'Selection.AutoFilter Field:=1, Criteria1:=ProfilRA
'Selection.AutoFilter Field:=2, Criteria1:=periodicite
'Selection.AutoFilter Field:=3, Criteria1:=Typeamortissement
'pour spread E1:E18369
'pour TAN G
'pour dvma I
Columns("G:G").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("Q1").Select
ActiveSheet.Paste
For i = 1 To 349 Step 12
Range("S" & i).Select
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-2]:R[11]C[-2])/100"
Next i
Range("S1:S360").Select
Selection.NumberFormat = "0.00%"
Selection.SpecialCells(xlCellTypeFormulas, 23).Select
Selection.Copy
Range("V2").Select
ActiveSheet.Paste
Range("M1").Select
Application.CutCopyMode = False
MsgBox ("Données crédits taux fixe importées avec succès")
Worksheets("Traitement").Select
Columns("I:I").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("AA1").Select
ActiveSheet.Paste
For i = 1 To 349 Step 12
Range("AC" & i).Select
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-2]:R[11]C[-2])"
Next i
Range("AC1:AC360").Select
Selection.SpecialCells(xlCellTypeFormulas, 23).Select
Selection.Copy
Range("AF2").Select
ActiveSheet.Paste
Range("A1").Select
Application.CutCopyMode = False
MsgBox ("DVMA importées avec succès.")
Worksheets("Traitement").Select
Rows("1:29").Select
Selection.Delete Shift:=xlUp
Range("A:I").Select
Range("E16").Activate
Selection.Clear
Range("C9").Select
Worksheets("TCI crédit").Select
GetData "S:\DCG\DCG_Commun\CNCE-Rac\Barèmes\2009\" & NomFichier, "CT_CAP", _
"B5:M17333", Sheets("Traitement").Range("A1"), True, False
Worksheets("Traitement").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "a"
Range("B1").Select
ActiveCell.FormulaR1C1 = "b"
Range("C1").Select
ActiveCell.FormulaR1C1 = 0.01
Range("D1").Select
ActiveCell.FormulaR1C1 = 0.015
Range("E1").Select
ActiveCell.FormulaR1C1 = 0.02
Range("F1").Select
ActiveCell.FormulaR1C1 = 0.025
Range("G1").Select
ActiveCell.FormulaR1C1 = 0.03
Range("H1").Select
ActiveCell.FormulaR1C1 = 0.035
Range("I1").Select
ActiveCell.FormulaR1C1 = 0
Range("J1").Select
ActiveCell.FormulaR1C1 = 0.005
Range("K1").Select
ActiveCell.FormulaR1C1 = 0.04
Range("L1").Select
ActiveCell.FormulaR1C1 = 0.045
Range("A1:L17428").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=ProfilRA
Selection.AutoFilter Field:=2, Criteria1:=Typeamortissement
Columns("C:L").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("AL1").Select
ActiveSheet.Paste
Range("AL1").Select
Application.CutCopyMode = False
Columns("AR:AR").Select
Selection.Copy
Columns("AL:AL").Select
Selection.Insert Shift:=xlToRight
Columns("AS:AS").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Selection.Copy
Columns("AM:AM").Select
Selection.Insert Shift:=xlToRight
Columns("AT:AT").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("AK1").Select
MsgBox ("Coût des CAP importé avec succès.")
'Fin:
Worksheets("Traitement").Select
Rows("1:29").Select
Selection.Delete Shift:=xlUp
Range("A😀D").Select
Range("E16").Activate
Selection.Clear
Range("C9").Select
Worksheets("TCI crédit").Select
NomFichier1 = InputBox("Veuillez saisir le nom du fichier d'où vont être importés les paramètres crédits du mois dernier" & vbCr & "Par exemple: Barèmes_RAC_Mai_2009_TRC.xls")
GetData "S:\DCG\DCG_Commun\CNCE-Rac\Barèmes\2009\" & NomFichier1, "BAREMES", _
"B5:J17333", Sheets("Traitement").Range("A1"), True, False
On Error GoTo Fin
If NomFichier1 = "" Then
GoTo Fin
End If
Worksheets("Traitement").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "a"
Range("B1").Select
ActiveCell.FormulaR1C1 = "b"
Range("C1").Select
ActiveCell.FormulaR1C1 = "c"
Range("D1").Select
ActiveCell.FormulaR1C1 = "swap"
Range("E1").Select
ActiveCell.FormulaR1C1 = "spread haut"
Range("F1").Select
ActiveCell.FormulaR1C1 = "spread bas"
Range("G1").Select
ActiveCell.FormulaR1C1 = "TAN haut"
Range("H1").Select
ActiveCell.FormulaR1C1 = "Tan bas"
Range("I1").Select
ActiveCell.FormulaR1C1 = "DVMA"
Range("A1:I17428").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=ProfilRA
Selection.AutoFilter Field:=2, Criteria1:=periodicite
Selection.AutoFilter Field:=3, Criteria1:=Typeamortissement
'pour spread E1:E18369
'pour TAN G
'pour dvma I
Columns("D😀").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("AZ1").Select
ActiveSheet.Paste
Worksheets("Traitement").Select
Columns("E:E").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("BC1").Select
ActiveSheet.Paste
MsgBox ("Données crédits taux révisable importées avec succès")
Worksheets("Traitement").Select
Columns("G:G").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("BF1").Select
ActiveSheet.Paste
MsgBox ("Données crédits taux fixe importées avec succès")
Worksheets("Traitement").Select
Columns("I:I").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("BI1").Select
ActiveSheet.Paste
MsgBox ("DVMA importées avec succès.")
Worksheets("Traitement").Select
Rows("1:29").Select
Selection.Delete Shift:=xlUp
Range("A😀D").Select
Range("E16").Activate
Selection.Clear
Range("C9").Select
Worksheets("TCI crédit").Select
GetData "S:\DCG\DCG_Commun\CNCE-Rac\Barèmes\2009\" & NomFichier1, "CT_CAP", _
"B5:M17333", Sheets("Traitement").Range("A1"), True, False
Worksheets("Traitement").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "a"
Range("B1").Select
ActiveCell.FormulaR1C1 = "b"
Range("C1").Select
ActiveCell.FormulaR1C1 = 0.01
Range("D1").Select
ActiveCell.FormulaR1C1 = 0.015
Range("E1").Select
ActiveCell.FormulaR1C1 = 0.02
Range("F1").Select
ActiveCell.FormulaR1C1 = 0.025
Range("G1").Select
ActiveCell.FormulaR1C1 = 0.03
Range("H1").Select
ActiveCell.FormulaR1C1 = 0.035
Range("I1").Select
ActiveCell.FormulaR1C1 = 0
Range("J1").Select
ActiveCell.FormulaR1C1 = 0.005
Range("K1").Select
ActiveCell.FormulaR1C1 = 0.04
Range("L1").Select
ActiveCell.FormulaR1C1 = 0.045
Range("A1:L17428").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=ProfilRA
Selection.AutoFilter Field:=2, Criteria1:=Typeamortissement
Columns("C:L").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("BL1").Select
ActiveSheet.Paste
Range("BL1").Select
Application.CutCopyMode = False
Columns("BR:BR").Select
Selection.Copy
Columns("BL:BL").Select
Selection.Insert Shift:=xlToRight
Columns("BS:BS").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Selection.Copy
Columns("BM:BM").Select
Selection.Insert Shift:=xlToRight
Columns("BT:BT").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("AK1").Select
MsgBox ("Coût des CAP importé avec succès.")
Worksheets("Traitement").Select
Rows("1:29").Select
Selection.Delete Shift:=xlUp
Range("A😀D").Select
Range("E16").Activate
Selection.Clear
Range("C9").Select
Worksheets("TCI crédit").Select
NomFichier2 = InputBox("Veuillez saisir le nom du fichier d'où vont être importés les paramètres crédits de l'avant dernier mois" & vbCr & "Par exemple: Barèmes_RAC_Mai_2009_TRC.xls")
GetData "S:\DCG\DCG_Commun\CNCE-Rac\Barèmes\2009\" & NomFichier2, "BAREMES", _
"B5:J17333", Sheets("Traitement").Range("A1"), True, False
On Error GoTo Fin
If NomFichier2 = "" Then
GoTo Fin
End If
Worksheets("Traitement").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "a"
Range("B1").Select
ActiveCell.FormulaR1C1 = "b"
Range("C1").Select
ActiveCell.FormulaR1C1 = "c"
Range("D1").Select
ActiveCell.FormulaR1C1 = "swap"
Range("E1").Select
ActiveCell.FormulaR1C1 = "spread haut"
Range("F1").Select
ActiveCell.FormulaR1C1 = "spread bas"
Range("G1").Select
ActiveCell.FormulaR1C1 = "TAN haut"
Range("H1").Select
ActiveCell.FormulaR1C1 = "Tan bas"
Range("I1").Select
ActiveCell.FormulaR1C1 = "DVMA"
Range("A1:I17428").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=ProfilRA
Selection.AutoFilter Field:=2, Criteria1:=periodicite
Selection.AutoFilter Field:=3, Criteria1:=Typeamortissement
'pour spread E1:E18369
'pour TAN G
'pour dvma I
Columns("D😀").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("BZ1").Select
ActiveSheet.Paste
Worksheets("Traitement").Select
Columns("E:E").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("CC1").Select
ActiveSheet.Paste
MsgBox ("Données crédits taux révisable importées avec succès")
Worksheets("Traitement").Select
Columns("G:G").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("CF1").Select
ActiveSheet.Paste
MsgBox ("Données crédits taux fixe importées avec succès")
Worksheets("Traitement").Select
Columns("I:I").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("CI1").Select
ActiveSheet.Paste
MsgBox ("DVMA importées avec succès.")
Worksheets("Traitement").Select
Rows("1:29").Select
Selection.Delete Shift:=xlUp
Range("A😀D").Select
Range("E16").Activate
Selection.Clear
Range("C9").Select
Worksheets("TCI crédit").Select
GetData "S:\DCG\DCG_Commun\CNCE-Rac\Barèmes\2009\" & NomFichier2, "CT_CAP", _
"B5:M17333", Sheets("Traitement").Range("A1"), True, False
Worksheets("Traitement").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "a"
Range("B1").Select
ActiveCell.FormulaR1C1 = "b"
Range("C1").Select
ActiveCell.FormulaR1C1 = 0.01
Range("D1").Select
ActiveCell.FormulaR1C1 = 0.015
Range("E1").Select
ActiveCell.FormulaR1C1 = 0.02
Range("F1").Select
ActiveCell.FormulaR1C1 = 0.025
Range("G1").Select
ActiveCell.FormulaR1C1 = 0.03
Range("H1").Select
ActiveCell.FormulaR1C1 = 0.035
Range("I1").Select
ActiveCell.FormulaR1C1 = 0
Range("J1").Select
ActiveCell.FormulaR1C1 = 0.005
Range("K1").Select
ActiveCell.FormulaR1C1 = 0.04
Range("L1").Select
ActiveCell.FormulaR1C1 = 0.045
Range("A1:L17428").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=ProfilRA
Selection.AutoFilter Field:=2, Criteria1:=Typeamortissement
Columns("C:L").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("TCI crédit").Select
Range("CL1").Select
ActiveSheet.Paste
Range("CL1").Select
Application.CutCopyMode = False
Columns("CR:CR").Select
Selection.Copy
Columns("CL:CL").Select
Selection.Insert Shift:=xlToRight
Columns("CS:CS").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Selection.Copy
Columns("CM:CM").Select
Selection.Insert Shift:=xlToRight
Columns("CT:CT").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("AK1").Select
MsgBox ("Coût des CAP importé avec succès.")
Worksheets("TCI crédit").Select
Range("B2").Select
ActiveCell.FormulaR1C1 = NomFichier
Worksheets("TCI crédit").Select
Range("B3").Select
ActiveCell.FormulaR1C1 = ProfilRA
Range("B4").Select
ActiveCell.FormulaR1C1 = periodicite
Range("B5").Select
ActiveCell.FormulaR1C1 = Typeamortissement
Worksheets("TCI crédit").Select
Range("C2").Select
ActiveCell.FormulaR1C1 = NomFichier1
Worksheets("TCI crédit").Select
Range("C3").Select
ActiveCell.FormulaR1C1 = ProfilRA
Range("C4").Select
ActiveCell.FormulaR1C1 = periodicite
Range("C5").Select
ActiveCell.FormulaR1C1 = Typeamortissement
Worksheets("TCI crédit").Select
Range("D2").Select
ActiveCell.FormulaR1C1 = NomFichier2
Worksheets("TCI crédit").Select
Range("D3").Select
ActiveCell.FormulaR1C1 = ProfilRA
Range("D4").Select
ActiveCell.FormulaR1C1 = periodicite
Range("D5").Select
ActiveCell.FormulaR1C1 = Typeamortissement
Fin:
Worksheets("Traitement").Select
Rows("1:29").Select
Selection.Delete Shift:=xlUp
Range("A😀D").Select
Range("E16").Activate
Selection.Clear
Range("C9").Select
Worksheets("TCI crédit").Select
End Sub