Bonjour
j'ai mis un code qui recupere des données dans un autre classeur et ca marche bien sauf que il est long, est il possible de le reduire svp ?
VOICI LE CODE
merci d'avance
j'ai mis un code qui recupere des données dans un autre classeur et ca marche bien sauf que il est long, est il possible de le reduire svp ?
VOICI LE CODE
VB:
Sub macro1()
b = Worksheets("NEW_VB_config").Range("o2")
c = Worksheets("NEW_VB_config").Range("o3")
d = Worksheets("NEW_VB_config").Range("o4")
g = Worksheets("NEW_VB_config").Range("o5")
h = Worksheets("NEW_VB_config").Range("o6")
k = Worksheets("NEW_VB_config").Range("o7")
l = Worksheets("NEW_VB_config").Range("o8")
m = Worksheets("NEW_VB_config").Range("o9")
n = Worksheets("NEW_VB_config").Range("o10")
o = Worksheets("NEW_VB_config").Range("o11")
p = Worksheets("NEW_VB_config").Range("o12")
a = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets("NEW_VB_config").Range("o2:o12") 'nom des 11 feuilles
For f = 1 To 11 'boucle sur les feuilles
If a(f, 1) <> "" And a(f, 1) = b Then 'feuille o2
derlin = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(b).Range("a65000").End(xlUp).Row
If derlin <> 1 Then
'test ligne
derliac2 = Workbooks("greogroire essai_V2.xlsm").Worksheets(b).Range("a65000").End(xlUp).Row
For i2 = 2 To derliac2
If Workbooks("greogroire essai_V2.xlsm").Worksheets(b).Cells(i2, 40) = "OMEGA 1" Then
test2 = Workbooks("greogroire essai_V2.xlsm").Worksheets(b).Cells(i2, 40).Row
End If
Next i2
If derlin > test2 Then
n2 = derlin - test2
Workbooks("greogroire essai_V2.xlsm").Worksheets(b).Rows(test2 + 1).Resize(n2).Insert
End If
'fin tets
For i = 2 To derlin
If Range("a" & i) <> "" And Worksheets(b).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(b).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(b).Cells(i, j) = Worksheets(b).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(b).Cells(i, 40) = "OMEGA 1"
End If
last1 = Workbooks("greogroire essai_V2.xlsm").Worksheets(b).Range("a" & i).Row + 1
Next i
Else
last11 = 2
End If
ElseIf a(f, 1) <> "" And a(f, 1) = c Then 'feuille o3
derlin1 = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(c).Range("a65000").End(xlUp).Row
If derlin1 <> 1 Then
'test ligne
derliac3 = Workbooks("greogroire essai_V2.xlsm").Worksheets(c).Range("a65000").End(xlUp).Row
For i3 = 2 To derliac3
If Workbooks("greogroire essai_V2.xlsm").Worksheets(c).Cells(i3, 40) = "OMEGA 1" Then
test3 = Workbooks("greogroire essai_V2.xlsm").Worksheets(c).Cells(i3, 40).Row
End If
Next i3
If derlin1 > test3 Then
n3 = derlin1 - test3
Workbooks("greogroire essai_V2.xlsm").Worksheets(c).Rows(test3 + 1).Resize(n3).Insert
End If
'fin tets
For i = 2 To derlin1
If Range("a" & i) <> "" And Worksheets(c).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(c).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(c).Cells(i, j) = Worksheets(c).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(c).Cells(i, 40) = "OMEGA 1"
End If
last2 = Workbooks("greogroire essai_V2.xlsm").Worksheets(c).Range("a" & i).Row + 1
Next i
Else
last2 = 2
End If
ElseIf a(f, 1) <> "" And a(f, 1) = d Then 'feuille o4
derlin2 = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(d).Range("a65000").End(xlUp).Row
If derlin2 <> 1 Then
'test ligne
derliac4 = Workbooks("greogroire essai_V2.xlsm").Worksheets(d).Range("a65000").End(xlUp).Row
For i4 = 2 To derliac4
If Workbooks("greogroire essai_V2.xlsm").Worksheets(d).Cells(i4, 40) = "OMEGA 1" Then
test4 = Workbooks("greogroire essai_V2.xlsm").Worksheets(d).Cells(i4, 40).Row
End If
Next i4
If derlin2 > test4 Then
n4 = derlin2 - test4
Workbooks("greogroire essai_V2.xlsm").Worksheets(d).Rows(test4 + 1).Resize(n4).Insert
End If
'fin tets
For i = 2 To derlin2
If Range("a" & i) <> "" And Worksheets(d).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(d).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(d).Cells(i, j) = Worksheets(d).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(d).Cells(i, 40) = "OMEGA 1"
End If
last3 = Workbooks("greogroire essai_V2.xlsm").Worksheets(d).Range("a" & i).Row + 1
Next i
Else
last3 = 2
End If
ElseIf a(f, 1) <> "" And a(f, 1) = g Then 'feuille o5
derlin3 = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(g).Range("a65000").End(xlUp).Row
If derlin3 <> 1 Then
'test ligne
derliac5 = Workbooks("greogroire essai_V2.xlsm").Worksheets(g).Range("a65000").End(xlUp).Row
For i5 = 2 To derliac5
If Workbooks("greogroire essai_V2.xlsm").Worksheets(g).Cells(i5, 40) = "OMEGA 1" Then
test5 = Workbooks("greogroire essai_V2.xlsm").Worksheets(g).Cells(i5, 40).Row
End If
Next i5
If derlin3 > test5 Then
n5 = derlin3 - test5
Workbooks("greogroire essai_V2.xlsm").Worksheets(g).Rows(test5 + 1).Resize(n5).Insert
End If
'fin tets
For i = 2 To derlin3
If Range("a" & i) <> "" And Worksheets(g).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(g).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(g).Cells(i, j) = Worksheets(g).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(g).Cells(i, 40) = "OMEGA 1"
End If
last4 = Workbooks("greogroire essai_V2.xlsm").Worksheets(g).Range("a" & i).Row + 1
Next i
Else
last4 = 2
End If
ElseIf a(f, 1) <> "" And a(f, 1) = h Then 'feuille o6
derlin4 = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(h).Range("a65000").End(xlUp).Row
If derlin4 <> 1 Then
'test ligne
derliac6 = Workbooks("greogroire essai_V2.xlsm").Worksheets(h).Range("a65000").End(xlUp).Row
For i6 = 2 To derliac6
If Workbooks("greogroire essai_V2.xlsm").Worksheets(h).Cells(i6, 40) = "OMEGA 1" Then
test6 = Workbooks("greogroire essai_V2.xlsm").Worksheets(h).Cells(i6, 40).Row
End If
Next i6
If derlin4 > test6 Then
n6 = derlin4 - test6
Workbooks("greogroire essai_V2.xlsm").Worksheets(h).Rows(test6 + 1).Resize(n6).Insert
End If
'fin tets
For i = 2 To derlin4
If Range("a" & i) <> "" And Worksheets(h).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(h).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(h).Cells(i, j) = Worksheets(h).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(h).Cells(i, 40) = "OMEGA 1"
End If
last5 = Workbooks("greogroire essai_V2.xlsm").Worksheets(h).Range("an" & i).Row + 1
Next i
Else
last5 = 2
End If
ElseIf a(f, 1) <> "" And a(f, 1) = k Then 'feuille o7
derlin5 = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(k).Range("a65000").End(xlUp).Row
If derlin5 <> 1 Then
'test ligne
derliac7 = Workbooks("greogroire essai_V2.xlsm").Worksheets(k).Range("a65000").End(xlUp).Row
For i7 = 2 To derliac7
If Workbooks("greogroire essai_V2.xlsm").Worksheets(k).Cells(i7, 40) = "OMEGA 1" Then
test7 = Workbooks("greogroire essai_V2.xlsm").Worksheets(k).Cells(i7, 40).Row
End If
Next i7
If derlin5 > test7 Then
n7 = derlin5 - test7
Workbooks("greogroire essai_V2.xlsm").Worksheets(k).Rows(test7 + 1).Resize(n7).Insert
End If
'fin tets
For i = 2 To derlin5
If Range("a" & i) <> "" And Worksheets(k).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(k).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(k).Cells(i, j) = Worksheets(k).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(k).Cells(i, 40) = "OMEGA 1"
End If
last6 = Workbooks("greogroire essai_V2.xlsm").Worksheets(k).Range("a" & i).Row + 1
Next i
Else
last6 = 2
End If
ElseIf a(f, 1) <> "" And a(f, 1) = l Then 'feuille o8
derlin6 = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(l).Range("a65000").End(xlUp).Row
If derlin6 <> 1 Then
'test ligne
derliac8 = Workbooks("greogroire essai_V2.xlsm").Worksheets(l).Range("a65000").End(xlUp).Row
For i8 = 2 To derliac8
If Workbooks("greogroire essai_V2.xlsm").Worksheets(l).Cells(i8, 40) = "OMEGA 1" Then
test8 = Workbooks("greogroire essai_V2.xlsm").Worksheets(l).Cells(i8, 40).Row
End If
Next i8
If derlin6 > test8 Then
n8 = derlin6 - test8
Workbooks("greogroire essai_V2.xlsm").Worksheets(l).Rows(test8 + 1).Resize(n8).Insert
End If
'fin tets
For i = 2 To derlin6
If Range("a" & i) <> "" And Worksheets(l).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(l).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(l).Cells(i, j) = Worksheets(l).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(l).Cells(i, 40) = "OMEGA 1"
End If
last7 = Workbooks("greogroire essai_V2.xlsm").Worksheets(l).Range("a" & i).Row + 1
Next i
Else
last7 = 2
End If
ElseIf a(f, 1) <> "" And a(f, 1) = m Then 'feuille o9
derlin7 = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(m).Range("a65000").End(xlUp).Row
If derlin7 <> 1 Then
'test ligne
derliac9 = Workbooks("greogroire essai_V2.xlsm").Worksheets(m).Range("a65000").End(xlUp).Row
For i9 = 2 To derliac9
If Workbooks("greogroire essai_V2.xlsm").Worksheets(m).Cells(i9, 40) = "OMEGA 1" Then
test9 = Workbooks("greogroire essai_V2.xlsm").Worksheets(m).Cells(i9, 40).Row
End If
Next i9
If derlin7 > test9 Then
n9 = derlin7 - test9
Workbooks("greogroire essai_V2.xlsm").Worksheets(m).Rows(test9 + 1).Resize(n9).Insert
End If
'fin tets
For i = 2 To derlin7
If Range("a" & i) <> "" And Worksheets(m).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(m).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(m).Cells(i, j) = Worksheets(m).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(m).Cells(i, 40) = "OMEGA 1"
End If
last8 = Workbooks("greogroire essai_V2.xlsm").Worksheets(m).Range("a" & i).Row + 1
Next i
Else
last8 = 2
End If
ElseIf a(f, 1) <> "" And a(f, 1) = n Then 'feuille o10
derlin8 = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(n).Range("a65000").End(xlUp).Row
If derlin8 <> 1 Then
'test ligne
derliac10 = Workbooks("greogroire essai_V2.xlsm").Worksheets(n).Range("a65000").End(xlUp).Row
For i10 = 2 To derliac10
If Workbooks("greogroire essai_V2.xlsm").Worksheets(n).Cells(i10, 40) = "OMEGA 1" Then
test10 = Workbooks("greogroire essai_V2.xlsm").Worksheets(n).Cells(i10, 40).Row
End If
Next i10
If derlin8 > test10 Then
n10 = derlin8 - test10
Workbooks("greogroire essai_V2.xlsm").Worksheets(n).Rows(test10 + 1).Resize(n10).Insert
End If
'fin tets
For i = 2 To derlin8
If Range("a" & i) <> "" And Worksheets(n).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(n).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(n).Cells(i, j) = Worksheets(m).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(n).Cells(i, 40) = "OMEGA 1"
End If
last9 = Workbooks("greogroire essai_V2.xlsm").Worksheets(n).Range("a" & i).Row + 1
Next i
Else
last9 = 2
End If
ElseIf a(f, 1) <> "" And a(f, 1) = o Then 'feuille o11
derlin9 = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(o).Range("a65000").End(xlUp).Row
If derlin9 <> 1 Then
'test ligne
derliac11 = Workbooks("greogroire essai_V2.xlsm").Worksheets(o).Range("a65000").End(xlUp).Row
For i11 = 2 To derliac11
If Workbooks("greogroire essai_V2.xlsm").Worksheets(o).Cells(i11, 40) = "OMEGA 1" Then
test11 = Workbooks("greogroire essai_V2.xlsm").Worksheets(o).Cells(i11, 40).Row
End If
Next i11
If derlin9 > test11 Then
n11 = derlin9 - test11
Workbooks("greogroire essai_V2.xlsm").Worksheets(o).Rows(test11 + 1).Resize(n11).Insert
End If
'fin tets
For i = 2 To derlin9
If Range("a" & i) <> "" And Worksheets(o).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(o).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(o).Cells(i, j) = Worksheets(o).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(o).Cells(i, 40) = "OMEGA 1"
End If
last10 = Workbooks("greogroire essai_V2.xlsm").Worksheets(o).Range("a" & i).Row + 1
Next i
Else
last10 = 2
End If
ElseIf a(f, 1) <> "" And a(f, 1) = p Then 'feuille o12
derlin10 = Workbooks("iOMEGA_Equipe_CDO_v4_6_01032019.xlsm").Worksheets(p).Range("a65000").End(xlUp).Row
If derlin10 <> 1 Then
'test ligne
derliac12 = Workbooks("greogroire essai_V2.xlsm").Worksheets(p).Range("a65000").End(xlUp).Row
For i12 = 2 To derliac12
If Workbooks("greogroire essai_V2.xlsm").Worksheets(p).Cells(i12, 40) = "OMEGA 1" Then
test12 = Workbooks("greogroire essai_V2.xlsm").Worksheets(p).Cells(i12, 40).Row
End If
Next i12
If derlin10 > test12 Then
n12 = derlin10 - test12
Workbooks("greogroire essai_V2.xlsm").Worksheets(p).Rows(test12 + 1).Resize(n12).Insert
End If
'fin tets
For i = 2 To derlin10
If Range("a" & i) <> "" And Worksheets(p).Cells(i, 1) <> Workbooks("greogroire essai_V2.xlsm").Worksheets(p).Cells(i, 1) Then
For j = 1 To 6
Workbooks("greogroire essai_V2.xlsm").Worksheets(p).Cells(i, j) = Worksheets(p).Cells(i, j)
Next j
Workbooks("greogroire essai_V2.xlsm").Worksheets(p).Cells(i, 40) = "OMEGA 1"
End If
last11 = Workbooks("greogroire essai_V2.xlsm").Worksheets(p).Range("a" & i).Row + 1
Next i
Else
last11 = 2
End If
End If
Next
MsgBox "Omega 1 terminé"
end sub
merci d'avance
Dernière édition: