Bonjour à tous,

Je viens vers vous car je bute sur une formule en VBA.

Je m'explique:
J'ai un onglet avec une base données qui s'appelle "BasedeDonnées".
Sur celle ci, divers informations , exemple Row 1 Nom, Row 2 Prenom, ect….

J'ai un autre onglet, qui s'appelle "Casiersafermer", qui va chercher via un bouton et du code VBA derrière, les informations dans la base données.
Pour être clair, voici la composition des cellules de l'onglet "Casierafermer"
Cellule F15, une réf posée manuellement (exp, FM1, FM2, FM3, ect….)
Cellule G15, le nom inséré automatiquement via mon bouton
Cellule H15, le prénom inséré automatiquement via mon bouton
Cellule I15, le Service de la personne inséré automatiquement via mon bouton
Cellule J15, Le poste occupé de la personne inséré automatiquement via mon bouton

En cliquant sur mon bouton, mon code regarde la cellule F15 et insère les informations sur la même ligne via ma base de donnée.

Jusque là mon code fonctionne correctement pas de souci.

Mais, sinon se ne serait pas drôle…. , le code vérifie également en plus de la cellule F15, la cellule F16, F17, F18, ect… jusqu'à F34

Lorsque je n'ai qu'une ou deux ref d'inscrit en F15 et F16, par exemple, il met un temps monstrueux car les autres cellules F17, F18, ect sont vide….

Je voudrait lui ajouter une fonction du style, si la cellule F15, F16, F17, ect jusqu'à F34 est vide, tu passes à l'étape suivante.
Ce qui lui permettrais de ne pas passer une plombe.

Voici mon code VBA:

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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
Sub miseajourcasiers()
Dim F1 As Worksheet
Dim F2 As Worksheet
Set F1 = Sheets("Casiersafermer")
Set F2 = Sheets("BasedeDonnées")
Dim plage As Range
Set plage = F2.Range("Q3:Q800")
codrecherché = F1.Range("F15").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G15") = F2.Cells(cell.Row, 1)
    F1.Range("H15") = F2.Cells(cell.Row, 2)
    F1.Range("I15") = F2.Cells(cell.Row, 9)
    F1.Range("J15") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F16").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G16") = F2.Cells(cell.Row, 1)
    F1.Range("H16") = F2.Cells(cell.Row, 2)
    F1.Range("I16") = F2.Cells(cell.Row, 9)
    F1.Range("J16") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F17").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G17") = F2.Cells(cell.Row, 1)
    F1.Range("H17") = F2.Cells(cell.Row, 2)
    F1.Range("I17") = F2.Cells(cell.Row, 9)
    F1.Range("J17") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F18").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G18") = F2.Cells(cell.Row, 1)
    F1.Range("H18") = F2.Cells(cell.Row, 2)
    F1.Range("I18") = F2.Cells(cell.Row, 9)
    F1.Range("J18") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F19").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G19") = F2.Cells(cell.Row, 1)
    F1.Range("H19") = F2.Cells(cell.Row, 2)
    F1.Range("I19") = F2.Cells(cell.Row, 9)
    F1.Range("J19") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F20").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G20") = F2.Cells(cell.Row, 1)
    F1.Range("H20") = F2.Cells(cell.Row, 2)
    F1.Range("I20") = F2.Cells(cell.Row, 9)
    F1.Range("J20") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F21").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G21") = F2.Cells(cell.Row, 1)
    F1.Range("H21") = F2.Cells(cell.Row, 2)
    F1.Range("I21") = F2.Cells(cell.Row, 9)
    F1.Range("J21") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F22").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G22") = F2.Cells(cell.Row, 1)
    F1.Range("H22") = F2.Cells(cell.Row, 2)
    F1.Range("I22") = F2.Cells(cell.Row, 9)
    F1.Range("J22") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F23").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G23") = F2.Cells(cell.Row, 1)
    F1.Range("H23") = F2.Cells(cell.Row, 2)
    F1.Range("I23") = F2.Cells(cell.Row, 9)
    F1.Range("J23") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F24").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G24") = F2.Cells(cell.Row, 1)
    F1.Range("H24") = F2.Cells(cell.Row, 2)
    F1.Range("I24") = F2.Cells(cell.Row, 9)
    F1.Range("J24") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F25").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G25") = F2.Cells(cell.Row, 1)
    F1.Range("H25") = F2.Cells(cell.Row, 2)
    F1.Range("I25") = F2.Cells(cell.Row, 9)
    F1.Range("J25") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F26").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G26") = F2.Cells(cell.Row, 1)
    F1.Range("H26") = F2.Cells(cell.Row, 2)
    F1.Range("I26") = F2.Cells(cell.Row, 9)
    F1.Range("J26") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F27").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G27") = F2.Cells(cell.Row, 1)
    F1.Range("H27") = F2.Cells(cell.Row, 2)
    F1.Range("I27") = F2.Cells(cell.Row, 9)
    F1.Range("J27") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F28").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G28") = F2.Cells(cell.Row, 1)
    F1.Range("H28") = F2.Cells(cell.Row, 2)
    F1.Range("I28") = F2.Cells(cell.Row, 9)
    F1.Range("J28") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F29").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G29") = F2.Cells(cell.Row, 1)
    F1.Range("H29") = F2.Cells(cell.Row, 2)
    F1.Range("I29") = F2.Cells(cell.Row, 9)
    F1.Range("J29") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F30").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G30") = F2.Cells(cell.Row, 1)
    F1.Range("H30") = F2.Cells(cell.Row, 2)
    F1.Range("I30") = F2.Cells(cell.Row, 9)
    F1.Range("J30") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F31").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G31") = F2.Cells(cell.Row, 1)
    F1.Range("H31") = F2.Cells(cell.Row, 2)
    F1.Range("I31") = F2.Cells(cell.Row, 9)
    F1.Range("J31") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F32").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G32") = F2.Cells(cell.Row, 1)
    F1.Range("H32") = F2.Cells(cell.Row, 2)
    F1.Range("I32") = F2.Cells(cell.Row, 9)
    F1.Range("J32") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F33").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G33") = F2.Cells(cell.Row, 1)
    F1.Range("H33") = F2.Cells(cell.Row, 2)
    F1.Range("I33") = F2.Cells(cell.Row, 9)
    F1.Range("J33") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
codrecherché = F1.Range("F34").Value
Application.ScreenUpdating = False
For Each cell In plage
 If cell.Value = codrecherché Then
    F1.Range("G34") = F2.Cells(cell.Row, 1)
    F1.Range("H34") = F2.Cells(cell.Row, 2)
    F1.Range("I34") = F2.Cells(cell.Row, 9)
    F1.Range("J34") = F2.Cells(cell.Row, 10)
 End If
 Next cell
    Application.ScreenUpdating = True
End Sub

Voilà, j'espère avoir été assez clair dans mon explication.

En vous remerciant d'avance.

Cordialement.