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
| Public Sub alim_listes()
Dim champ1 As Range, champ2 As Range
Dim Tblo1() As Variant, Tblo2() As Variant
Dim l1 As Byte, l2 As Byte
Dim i As Byte, j As Byte
'facultatif
'variables affectées aux listes
Set champ1 = Worksheets("Liste 1").Range("B1:B23")
Set champ2 = Worksheets("Liste 2").Range("B1:B23")
With Worksheets(1)
'effacement de l'ancien résultat
.Range(.Range("G1"), .Range("G1").End(xlDown)).ClearContents
'variables à prendre en compte
l1 = .Range("C26").Value
l2 = .Range("D26").Value
End With
'alimentation des variables Tableau
For i = 1 To l1
ReDim Preserve Tblo1(1 To i)
Tblo1(i) = champ1.Cells(i, 1)
Next i
For j = 1 To l2
ReDim Preserve Tblo2(1 To j)
Tblo2(j) = champ2.Cells(j, 1)
Next j
'résultat en fonction de la comparaison des cellules C26 et D26
With Worksheets(1).Range("G1")
If l1 > l2 Then
.Resize(UBound(Tblo1), 1).Value = WorksheetFunction.Transpose(Tblo1)
.Offset(UBound(Tblo1), 0).Resize(UBound(Tblo2), 1).Value = WorksheetFunction.Transpose(Tblo2)
Else
.Resize(UBound(Tblo2), 1).Value = WorksheetFunction.Transpose(Tblo2)
.Offset(UBound(Tblo2), 0).Resize(UBound(Tblo1), 1).Value = WorksheetFunction.Transpose(Tblo1)
End If
End With
'variables réinitialisées
Set champ2 = Nothing
Set champ1 = Nothing
End Sub |
Partager