• Initiateur de la discussion Initiateur de la discussion pott
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

P

pott

Guest
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

Visiblement ce qu'on vous dit ne vous intéresse guère, tant pis pour vous 🙄

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

Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD
Assurez vous de marquer un message comme solution pour une meilleure transparence.

Discussions similaires

Réponses
5
Affichages
373
Réponses
2
Affichages
148
Réponses
6
Affichages
169
Retour