Bonjour à tous,
Voici mon problème , ma macro me demande d'ouvrir un fichier avec une boite de dialogue cependant quand je clique sur annuler, j'ai l'erreur 9 : l'indice n'appartient pas la sélection.
Voici le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Sub importation()
    Application.ScreenUpdating = False
 
    Dim i, k, m, n, p, v, d, f, s, q, l As Integer
 
    Dim Fichier
    Dim col_2 As Range
    Dim Plage As Range
    Dim Cel As Range
 
 
    'remise à zéro la feuille import sap
 
    Workbooks("A320NLG NEO A320NLG delivery Auto").Sheets("import sap").Columns("A:AY").Delete Shift:=xlToLeft
 
    'Importation des données sap dans le fichier (feuille import sap)
 
    If MsgBox("Voulez-vous importer les données?", vbYesNo, "Importation") = vbYes Then
            Fichier = Application.GetOpenFilename("Fichiers Excel(*.xls; *.xlsx; *.xlsm), *.xls; *.xlsx; *.xlsm")
 
                On Error GoTo Annuler
 
                    For m = 1 To UBound(Fichier)
                        If Mid(Fichier(m), InStrRev(Fichier(m), "\") + 1) <> ThisWorkbook.Name Then
 
                            On Error Resume Next
 
                            Workbooks.Open Fichier(m)
 
                        Else
 
                            MsgBox "le fichier " & ThisWorkbook.Name & " est déjà ouvert"
                        End If
 
                    Next m
 
Annuler:
 
    'copie des données du fichier extrait d'SAP vers le fichier A320NLGdelivery
 
            Workbooks("Feuille de calcul dans Basis (1).xlsx").Sheets("Feuil1").Activate
 
            Union(Columns(2), Columns(5), Columns(27), Columns(29), Columns(30)).Copy
 
    'coller les données dans le fichier A320NLGdelivery
 
            Workbooks("A320NLG NEO A320NLG delivery Auto.xlsm").Activate
 
            Sheets("import sap").Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 
    'supprimer les doublons sur l'ordre de fabrication
 
            Sheets("import sap").Range("A2", "E1000").RemoveDuplicates Columns:=Array(2)
 
    'mettre le format date courte pour la DDB et la DDO
 
            Sheets("import sap").Columns("D:E").NumberFormat = "m/d/yyyy"
 
    'extraction des données SAP vers le fichier import sap / mise en forme pour en faciliter l'exploitation
 
            For k = 2 To 500 Step 1
 
                If Sheets("import sap").Range("A" & k).Value <> 0 Then
 
                    Sheets("import sap").Cells(k, 6).FormulaR1C1 = "=MID(RC[-3],5,LEN(RC[-3]))"
 
                        For Each ws In ActiveWorkbook.Worksheets
 
                            With ws.Range("F" & k)
 
                                .NumberFormat = "0"
 
                                .Value = .Value
 
                            End With
 
                        Next
 
                End If
 
            Next k
 
 
    'mise en forme des données pour en faciliter l'exploitation
 
            For i = 1 To 500 Step 1
 
                If Sheets("import sap").Range("A" & i).Value <> 0 Then
 
                    Sheets("import sap").Cells(i, 2).Copy Destination:=Sheets("import sap").Cells(i, 7)
 
                    Sheets("import sap").Cells(i, 4).Copy Destination:=Sheets("import sap").Cells(i, 8)
 
                    Sheets("import sap").Cells(i, 5).Copy Destination:=Sheets("import sap").Cells(i, 9)
 
                    Sheets("import sap").Cells(i, 1).Copy Destination:=Sheets("import sap").Cells(i, 10)
 
                    Sheets("import sap").Cells(i, 11).FormulaR1C1 = "=CONCATENATE(RC[-5],RC[-10])"
 
                    Sheets("import sap").Cells(i, 12).Value = "OK"
                End If
 
            Next i
 
            Sheets("import sap").Columns("G:G").EntireColumn.AutoFit
 
    'détection des boublons sur le code msn
 
                With Worksheets("import sap")
                    Set Plage = .Range(.Cells(2, 6), .Cells(.Rows.Count, 6).End(xlUp))
 
                End With
            For Each Cel In Plage
 
                If Application.CountIf(Plage, Cel.Value) > 1 Then
 
                    Cel.Interior.ColorIndex = 3
 
                End If
 
            Next Cel
 
 
            For p = 2 To 500 Step 1
 
                If Sheets("import sap").Range("F" & p).Interior.ColorIndex = 3 Then
 
                    Sheets("import sap").Cells(p, 7).Value = "Doublon"
 
                    Sheets("import sap").Cells(p, 8).Value = "Doublon"
 
                    Sheets("import sap").Cells(p, 9).Value = "Doublon"
 
                End If
            Next p
 
    'mise à jour des colonnes OF - DDO - DDB
 
            For v = 4 To 500 Step 1
 
                If Sheets("Feuil1").Range("A" & v).Value <> "" Then
 
                    Sheets("Feuil1").Cells(v, 12).FormulaR1C1 = "=IFERROR((VLOOKUP(RC[-8],'import sap'!C6:C9,2,FALSE)),""NOT FOUND"")"
 
                    Sheets("Feuil1").Cells(v, 13).FormulaR1C1 = "=IFERROR((VLOOKUP(RC[-9],'import sap'!C6:C9,3,FALSE)),""NOT FOUND"")"
 
                    Sheets("Feuil1").Cells(v, 14).FormulaR1C1 = "=IFERROR((VLOOKUP(RC[-10],'import sap'!C6:C9,4,FALSE)),""NOT FOUND"")"
 
                End If
 
            Next v
 
   ' récupération des données concernant les rechanges
 
            Set col_2 = Worksheets("feuil1").Range("D1:D500")
 
            With ThisWorkbook.Sheets("import sap")
 
                For d = 2 To 500 Step 1
 
                f = Sheets("Feuil1").Cells(Rows.Count, "D").End(xlUp).Row + 1
 
                    If Application.CountIf(col_2, .Range("F" & d).Value) = 0 Then
 
                        Sheets("feuil1").Range("D" & f) = Sheets("import sap").Range("F" & d).Value
 
                f = f + 1
 
                    End If
 
                Next d
 
            End With
 
                s = Sheets("Feuil1").Cells(Rows.Count, "E").End(xlUp).Row + 1
 
                q = Sheets("Feuil1").Cells(Rows.Count, "D").End(xlUp).Row + 1
 
 
            For l = s To q Step 1
 
                Sheets("Feuil1").Cells(l, 5).FormulaR1C1 = "=IF(MID(RC[-1],1,4)=""RECH"",(VLOOKUP(RC[-1],'import sap'!C6:C12,5,FALSE)),"""")"
 
                Sheets("Feuil1").Cells(l, 12).FormulaR1C1 = "=IF(MID(RC[-8],1,4)=""RECH"",(VLOOKUP(RC[-8],'import sap'!C6:C12,2,FALSE)),"""")"
 
                Sheets("Feuil1").Cells(l, 13).FormulaR1C1 = "=IF(MID(RC[-9],1,4)=""RECH"",(VLOOKUP(RC[-9],'import sap'!C6:C12,4,FALSE)),"""")"
 
                Sheets("Feuil1").Cells(l, 14).FormulaR1C1 = "=IF(MID(RC[-10],1,4)=""RECH"",(VLOOKUP(RC[-10],'import sap'!C6:C12,3,FALSE)),"""")"
 
                Sheets("Feuil1").Cells(l, 6).FormulaR1C1 = "=IF(MID(RC[-2],1,4)=""RECH"",0,"""")"
 
                Sheets("Feuil1").Range("A5:Q5").Copy
 
                Sheets("Feuil1").Range("A" & l, "Q" & l).PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 
            Next l
 
            MsgBox ("Importation réussie")
 
    Else:
            MsgBox ("Importation annulée")
 
    End If
 
    Sheets("Feuil1").Select
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
Merci pour votre aide...