permuter la fonction somme

gianni59

XLDnaute Nouveau
bonjour tout le monde
une personne pour m 'aider svp
je bloque avec la fonction somme pour creer une macro
j 'ai une ligne de 9 chiffres et je voudrai additionner
et afficher le resultat de deux cellules de toutes les combinaison possible de c'est 9 chiffres.
merci pour l aide
 

Pièces jointes

  • somme.xls
    13.5 KB · Affichages: 66
  • somme.xls
    13.5 KB · Affichages: 68
  • somme.xls
    13.5 KB · Affichages: 66

KenDev

XLDnaute Impliqué
Re : permuter la fonction somme

Bonjour Gianni, Hoerwind, Monique, Mécano,

Une solution par fonction vba, qui pourra être utile si le nombre d'entrées est variable. Les données doivent être sur une ligne ou sur une colonne.

VB:
Option Explicit

Function SommeC2#(R As Range, n&)
    Dim c1 As Range, c2 As Range, c&, o%
    If (R.Columns.Count > 1 And R.Rows.Count > 1) Or R.Count = 1 Then
        SommeC2 = CVErr(xlErrRef)
        Exit Function
    End If
    If n < 1 Or n > WorksheetFunction.Combin(R.Count, 2) Then Exit Function
     If R.Columns.Count > 1 Then o = 1
     For Each c1 In R
        For Each c2 In R
            If Not (c1.Row = c2.Row And c1.Column = c2.Column) Then
                Select Case o
                    Case 1
                        If c2.Column > c1.Column Then
                            SommeC2 = c1 + c2
                            c = c + 1
                            If c = n Then Exit Function
                        End If
                    Case 0
                        If c2.Row > c1.Row Then
                            SommeC2 = c1 + c2
                            c = c + 1
                            If c = n Then Exit Function
                        End If
                End Select
            End If
        Next c2
    Next c1
End Function

Cordialement

KD
 

Pièces jointes

  • Copie de somme.xls
    36.5 KB · Affichages: 58
  • Copie de somme.xls
    36.5 KB · Affichages: 59
  • Copie de somme.xls
    36.5 KB · Affichages: 58

Discussions similaires

Réponses
8
Affichages
440

Statistiques des forums

Discussions
312 215
Messages
2 086 326
Membres
103 180
dernier inscrit
Vcr