XL 2019 Combinaison de valeur sans doublon

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 !

NewTeam

XLDnaute Nouveau
Bonjour,
Etant nouveau sur ce forum, je vais essayer de m'exprimer du mieux possible.
J'ai 7 valeurs d'équipements
FoilHeavyHullLightRadioSkinWinch
et je cherche à trouver toutes les combinaisons possible tout en respectant l'ordre de mes valeurs. Le résultat peut aller de 1 à 7 valeurs combinés avec un séparateur de "," .
Merci d'avance pour votre aide précieuse.
 
Bonsoir NewTeam, bienvenue sur XLD,

Je n'ai pas cherché mais ce problème a certainement déjà été traité.

Voyez le fichier joint et cette macro brute de fonderie :
VB:
Sub Combinaisons()
Dim liste, ub%, s$, col%, lig&, a%, b%, c%, d%, e%, f%
liste = Array("Foil", "Heavy", "Hull", "Light", "Radio", "Skin", "Winch")
ub = UBound(liste)
s = ", "
Application.ScreenUpdating = False
Rows("2:" & Rows.Count).ClearContents 'RAZ
'---1 mot---
col = 1: lig = 2
Cells(lig, col).Resize(ub + 1) = Application.Transpose(liste)
'---2 mots---
col = 2: lig = 2
For a = 0 To ub - 1
    For b = a + 1 To ub
        Cells(lig, col) = liste(a) & s & liste(b)
        lig = lig + 1
Next b, a
'---3 mots---
col = 3: lig = 2
For a = 0 To ub - 2
    For b = a + 1 To ub - 1
        For c = b + 1 To ub
            Cells(lig, col) = liste(a) & s & liste(b) & s & liste(c)
            lig = lig + 1
Next c, b, a
'---4 mots---
col = 4: lig = 2
For a = 0 To ub - 3
    For b = a + 1 To ub - 2
        For c = b + 1 To ub - 1
            For d = c + 1 To ub
                Cells(lig, col) = liste(a) & s & liste(b) & s & liste(c) & s & liste(d)
                lig = lig + 1
Next d, c, b, a
'---5 mots---
col = 5: lig = 2
For a = 0 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
                    Cells(lig, col) = liste(a) & s & liste(b) & s & liste(c) & s & liste(d) & s & liste(e)
                    lig = lig + 1
Next e, d, c, b, a
'---6 mots---
col = 6: lig = 2
For a = 0 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
                        Cells(lig, col) = liste(a) & s & liste(b) & s & liste(c) & s & liste(d) & s & liste(e) & s & liste(f)
                        lig = lig + 1
Next f, e, d, c, b, a
'---7 mots---
col = 7: lig = 2
Cells(lig, col) = Join(liste, s)
Columns.AutoFit 'ajustement largeurs
End Sub
Avec 7 éléments le nombre total de combinaisons est 2^7-1 = 127.

La macro est améliorable en terme de rapidité.

A+
 

Pièces jointes

- 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
Retour