quelles valeurs

pott

XLDnaute Nouveau
bonjour
je cherche une solution pour trouver les valeurs d'une liste donnée de factures par rapport un un encaissement.

merci
 

Pièces jointes

  • exemple.xlsx
    9 KB · Affichages: 7

job75

XLDnaute Barbatruc
Visiblement ce qu'on vous dit ne vous intéresse guère, tant pis pour vous :rolleyes:

Dans le fichier joint je sors l'artillerie lourde puisque toutes les combinaisons sont étudiées pour un maximum de 7 factures :
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cible, t, ub&, a&, n%, b&, c&, d&, e&, f&, g&
cible = [D2]
t = [B1].CurrentRegion.Resize(, 2) 'matrice, plus rapide
Application.EnableEvents = False 'désactive les évènements
[H2:XFD8].ClearContents 'RAZ
ub = UBound(t)
Select Case [F2]
    Case 1
        For a = 2 To ub
            If t(a, 1) = cible Then
                Range("H2").Offset(, n) = t(a, 1)
                n = n + 1
            End If
        Next a
    Case 2
        For a = 2 To ub - 1
            For b = a + 1 To ub
                If t(a, 1) + t(b, 1) = cible Then
                    Range("H2").Offset(, n) = t(a, 1)
                    Range("H3").Offset(, n) = t(b, 1)
                    n = n + 1
                End If
        Next b, a
    Case 3
        For a = 2 To ub - 2
            For b = a + 1 To ub - 1
                For c = b + 1 To ub
                    If t(a, 1) + t(b, 1) + t(c, 1) = cible Then
                        Range("H2").Offset(, n) = t(a, 1)
                        Range("H3").Offset(, n) = t(b, 1)
                        Range("H4").Offset(, n) = t(c, 1)
                        n = n + 1
                    End If
        Next c, b, a
    Case 4
        For a = 2 To ub - 3
            For b = a + 1 To ub - 2
                For c = b + 1 To ub - 1
                    For d = c + 1 To ub
                        If t(a, 1) + t(b, 1) + t(c, 1) + t(d, 1) = cible Then
                            Range("H2").Offset(, n) = t(a, 1)
                            Range("H3").Offset(, n) = t(b, 1)
                            Range("H4").Offset(, n) = t(c, 1)
                            Range("H5").Offset(, n) = t(d, 1)
                            n = n + 1
                        End If
        Next d, c, b, a
    Case 5
        For a = 2 To ub - 4
            For b = a + 1 To ub - 3
                For c = b + 1 To ub - 2
                    For d = c + 1 To ub - 1
                        For e = d + 1 To ub
                            If t(a, 1) + t(b, 1) + t(c, 1) + t(d, 1) + t(e, 1) = cible Then
                                Range("H2").Offset(, n) = t(a, 1)
                                Range("H3").Offset(, n) = t(b, 1)
                                Range("H4").Offset(, n) = t(c, 1)
                                Range("H5").Offset(, n) = t(d, 1)
                                Range("H6").Offset(, n) = t(e, 1)
                                n = n + 1
                            End If
        Next e, d, c, b, a
    Case 6
        For a = 2 To ub - 5
            For b = a + 1 To ub - 4
                For c = b + 1 To ub - 3
                    For d = c + 1 To ub - 2
                        For e = d + 1 To ub - 1
                            For f = e + 1 To ub
                                If t(a, 1) + t(b, 1) + t(c, 1) + t(d, 1) + t(e, 1) + t(f, 1) = cible Then
                                    Range("H2").Offset(, n) = t(a, 1)
                                    Range("H3").Offset(, n) = t(b, 1)
                                    Range("H4").Offset(, n) = t(c, 1)
                                    Range("H5").Offset(, n) = t(d, 1)
                                    Range("H6").Offset(, n) = t(e, 1)
                                    Range("H7").Offset(, n) = t(f, 1)
                                    n = n + 1
                                End If
        Next f, e, d, c, b, a
    Case 7
        For a = 2 To ub - 6
            For b = a + 1 To ub - 5
                For c = b + 1 To ub - 4
                    For d = c + 1 To ub - 3
                        For e = d + 1 To ub - 2
                            For f = e + 1 To ub - 1
                                For g = f + 1 To ub
                                    If t(a, 1) + t(b, 1) + t(c, 1) + t(d, 1) + t(e, 1) + t(f, 1) + t(g, 1) = cible Then
                                        Range("H2").Offset(, n) = t(a, 1)
                                        Range("H3").Offset(, n) = t(b, 1)
                                        Range("H4").Offset(, n) = t(c, 1)
                                        Range("H5").Offset(, n) = t(d, 1)
                                        Range("H6").Offset(, n) = t(e, 1)
                                        Range("H7").Offset(, n) = t(f, 1)
                                        Range("H8").Offset(, n) = t(g, 1)
                                        n = n + 1
                                    End If
        Next g, f, e, d, c, b, a

End Select
Application.EnableEvents = True 'réactive les évènements
End Sub
 

Pièces jointes

  • exemple(1).xlsm
    26.4 KB · Affichages: 9
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
314 079
Messages
2 105 474
Membres
109 375
dernier inscrit
anderson2