Somme si ensemble VBA

bonjour

j'ai écrit une macro qui utilise somme-si-ENS je n'ai pas de problème particulier sur le fonctionnement de la macro. Mais j'ai quand même une question.

Etant limité sur le cumul de somme-si-ENS dans la macro et que je suis obligé de répéter ma ligne pour chaque référence de k4:k10 en les additionnant afin d'avoir le résultat escompter voir code si dessous.

Serait il possible de déclarer l'ensemble des cellules de k4:k10 en variable pour n'avoir plus qu'une ligne.

c'est cette partie de la macro

Sheets("Housse").Range("c2:c15000"), "=" & Cells(5, 11) - si possible remplacer & cell(5,11) par une variable comprenant la zone k4:k10

merci d'avance pour votre aide

ci joint le fichier

Cells(7, 15).Value = (Application.WorksheetFunction.SumIfs(Sheets("Housse").Range("h2:h15000"), _
Sheets("Housse").Range("c2:c15000"), "=" & Cells(4, 11), _
Sheets("Housse").Range("g2:g15000"), "=" & Cells(2, 15)) / 1000 + _
 _
Application.WorksheetFunction.SumIfs(Sheets("Housse").Range("h2:h15000"), _
Sheets("Housse").Range("c2:c15000"), "=" & Cells(5, 11), _
Sheets("Housse").Range("g2:g15000"), "=" & Cells(2, 15)) / 1000 + _
 _
Application.WorksheetFunction.SumIfs(Sheets("Housse").Range("h2:h15000"), _
Sheets("Housse").Range("c2:c15000"), "=" & Cells(6, 11), _
Sheets("Housse").Range("g2:g15000"), "=" & Cells(2, 15)) / 1000 + _
 _
Application.WorksheetFunction.SumIfs(Sheets("Housse").Range("h2:h15000"), _
Sheets("Housse").Range("c2:c15000"), "=" & Cells(7, 11), _
Sheets("Housse").Range("g2:g15000"), "=" & Cells(2, 15)) / 1000 + _
 _
Application.WorksheetFunction.SumIfs(Sheets("Housse").Range("h2:h15000"), _
Sheets("Housse").Range("c2:c15000"), "=" & Cells(8, 11), _
Sheets("Housse").Range("g2:g15000"), "=" & Cells(2, 15)) / 1000 + _
 _
Application.WorksheetFunction.SumIfs(Sheets("Housse").Range("h2:h15000"), _
Sheets("Housse").Range("c2:c15000"), "=" & Cells(9, 11), _
Sheets("Housse").Range("g2:g15000"), "=" & Cells(2, 15)) / 1000) / Cells(15, 11).Value

Cells(8, 15).Value = Application.WorksheetFunction.SumIfs(Sheets("Housse").Range("h2:h15000"), _
Sheets("Housse").Range("c2:c15000"), "=" & Cells(10, 11), _
Sheets("Housse").Range("g2:g15000"), "=" & Cells(2, 15)) / 1000 / Cells(15, 11).Value

Cells(4, 15).Value = Cells(7, 15).Value + Cells(8, 15).Value

Bonjour,

Une proposition sans VBA à étudier.

Cdlt.

Bonjour

Voici une idée pour la première ligne de ta macro (donc ligne 3)

For i = 15 To 17
With Sheets("Housse")
    .Cells(3, i).Value = (Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), .Range("c2:c15000"), "=" & .Cells(2, 11), .Range("g2:g15000"), "=" & .Cells(2, i)) / 1000 + _
Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), .Range("c2:c15000"), "=" & .Cells(3, 11), .Range("g2:g15000"), "=" & .Cells(2, i)) / 1000) / .Cells(15, 11).Value
End With
Next

Crdlt

Bonjour

Merci à vous 2 pour vos réponses, mais j'ai vraiment besoin de la macro.

Dan

J’ai bien compris comment fonctionne ta macro mais ce que cherche

Quand j'écris c'est partie

.Range("c2:c15000"), "=" & .Cells(2, 11), 

au lieu de mettre .cells( 2,11) dans la fonction suivante .cells( 3,11) puis 4,11 pour obtenir la somme de toutes mes références

Je voudrais savoir si il y a moyen de déclarer les lignes de 3 à 10

Merci pour votre aide

Cordialement

Philippe

Re

Essaie comme ceci :

Sub calculhousse()
Dim i As Byte, j As Byte
Dim k As Double
'on calcule les besoins de bobine en petite housse  / semaine
'sem
With Sheets("Housse")
    For i = 15 To 17
        .Cells(3, i).Value = (Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), .Range("c2:c15000"), "=" & .Cells(2, 11), .Range("g2:g15000"), "=" & .Cells(2, i)) / 1000 + _
    Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), .Range("c2:c15000"), "=" & .Cells(3, 11), .Range("g2:g15000"), "=" & .Cells(2, i)) / 1000) / .Cells(15, 11).Value

    Next

    'on calcule les besoins de bobine en grande housse  / semaine
    'sem

    For j = 4 To 9
        k = (Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), _
        .Range("c2:c15000"), "=" & .Cells(j, 11), _
        .Range("g2:g15000"), "=" & .Cells(2, 15)) / 1000) + k
    Next

    Cells(4, 15).Value = k / .Cells(15, 11).Value + Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), _
    .Range("c2:c15000"), "=" & .Cells(10, 11), _
    .Range("g2:g15000"), "=" & .Cells(2, 15)) / 1000 / .Cells(15, 11).Value

    'sem +1

    k = 0
    For j = 4 To 9
        k = (Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), _
        .Range("c2:c15000"), "=" & .Cells(j, 11), _
        .Range("g2:g15000"), "=" & .Cells(2, 16)) / 1000) + k
    Next

    .Cells(4, 16).Value = k / .Cells(15, 11).Value + Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), _
    .Range("c2:c15000"), "=" & .Cells(10, 11), _
    .Range("g2:g15000"), "=" & .Cells(2, 16)) / 1000 / .Cells(15, 11).Value

    'sem + 2

    k = 0
    For j = 4 To 9
        k = (Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), _
        .Range("c2:c15000"), "=" & .Cells(j, 11), _
        .Range("g2:g15000"), "=" & .Cells(2, 17)) / 1000) + k
    Next

    .Cells(4, 17).Value = k / .Cells(15, 11).Value + Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), _
    .Range("c2:c15000"), "=" & .Cells(10, 11), _
    .Range("g2:g15000"), "=" & .Cells(2, 17)) / 1000 / .Cells(15, 11).Value
End With
End Sub

Code un peu plus court mais cela reste compréhensible à l'analyse

Cordialement

bonjour dan

j'ai un peut de mal avec ton code , malgrés ça j'ai réussi à le comprendre la logique et je l'ai un peut modifié ta solution pour le calcul de la grande housse, le code à l'air de fonctionner

quand penses tu?

cordialement

philippe

Sub test()

Dim i As Byte, j As Byte
Dim k As Double
'on calcule les besoins de bobine en petite housse  / semaine
'sem
With Sheets("Housse")
    For i = 15 To 17

        .Cells(3, i).Value = (Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), .Range("c2:c15000"), "=" & .Cells(2, 11), .Range("g2:g15000"), "=" & .Cells(2, i)) / 1000 + _
    Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), .Range("c2:c15000"), "=" & .Cells(3, 11), .Range("g2:g15000"), "=" & .Cells(2, i)) / 1000) / .Cells(15, 11).Value

    Next

    'on calcule les besoins de bobine en grande housse  / semaine
    'sem

   For j = 4 To 10
        k = (Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), _
        .Range("c2:c15000"), "=" & .Cells(j, 11), _
        .Range("g2:g15000"), "=" & .Cells(2, 15)) / 1000) + k
    Next

    Cells(4, 15).Value = k / .Cells(15, 11).Value

    'sem +1

   k = 0
    For j = 4 To 10
        k = (Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), _
        .Range("c2:c15000"), "=" & .Cells(j, 11), _
        .Range("g2:g15000"), "=" & .Cells(2, 16)) / 1000) + k
    Next

    .Cells(4, 16).Value = k / .Cells(15, 11).Value

    'sem + 2

    k = 0
    For j = 4 To 10

        k = (Application.WorksheetFunction.SumIfs(.Range("h2:h15000"), _
        .Range("c2:c15000"), "=" & .Cells(j, 11), _
        .Range("g2:g15000"), "=" & .Cells(2, 17)) / 1000) + k
    Next

    .Cells(4, 17).Value = k / .Cells(15, 11).Value

End With

End Sub

re

Oui cela fonctionne effectivement comme cela aussi.

Je me suis contenté de modifier ton code afin de le raccourcir sans trop analyser plus loin

Si ok, oublie pas de cloturer le fil en cliquant sur le V vert à coté du bouton EDITER

Crdlt

merci pour tout

philippe

Rechercher des sujets similaires à "somme ensemble vba"