Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

code plus simple ?

9 réponses
Avatar
eric.zzzz
Bonjour,
Je constate que je r=E9p=E8te 6 fois la m=EAme chose, Y a-t-il moyen de
faire plus simple ?
DLastRow =3D Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) =3D "SOMME"
WorksheetFunction.Sum (Range("T2:T" & DLastRow))
Range("T" & DLastRow + 1) =3D WorksheetFunction.Sum(Range("T2:T"
& DLastRow))
WorksheetFunction.Sum (Range("U2:U" & DLastRow))
Range("U" & DLastRow + 1) =3D WorksheetFunction.Sum(Range("U2:U"
& DLastRow))
WorksheetFunction.Sum (Range("Z2:Z" & DLastRow))
Range("Z" & DLastRow + 1) =3D WorksheetFunction.Sum(Range("Z2:Z"
& DLastRow))
WorksheetFunction.Sum (Range("AB2:AB" & DLastRow))
Range("AB" & DLastRow + 1) =3D
WorksheetFunction.Sum(Range("AB2:AB" & DLastRow))
WorksheetFunction.Sum (Range("AC2:AC" & DLastRow))
Range("AC" & DLastRow + 1) =3D
WorksheetFunction.Sum(Range("AC2:AC" & DLastRow))
WorksheetFunction.Sum (Range("AE2:AE" & DLastRow))
Range("AE" & DLastRow + 1) =3D
WorksheetFunction.Sum(Range("AE2:AE" & DLastRow))

Merci d'avance
Eric

9 réponses

Avatar
isabelle
bonjour Eric,


DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"

col = Array(20, 21, 26, 28, 29, 30)
For i = 0 To 5
WorksheetFunction.Sum Range(Cells(2, col(i)), Cells(DLastRow, col(i)))
Cells(DLastRow + 1, col(i)) = WorksheetFunction.Sum(Range(Cells(2, col(i)), Cells(DLastRow, col(i))))
Next


isabelle

Bonjour,
Je constate que je répète 6 fois la même chose, Y a-t-il moyen de
faire plus simple ?
DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"
WorksheetFunction.Sum (Range("T2:T" & DLastRow))
Range("T" & DLastRow + 1) = WorksheetFunction.Sum(Range("T2:T"
& DLastRow))
WorksheetFunction.Sum (Range("U2:U" & DLastRow))
Range("U" & DLastRow + 1) = WorksheetFunction.Sum(Range("U2:U"
& DLastRow))
WorksheetFunction.Sum (Range("Z2:Z" & DLastRow))
Range("Z" & DLastRow + 1) = WorksheetFunction.Sum(Range("Z2:Z"
& DLastRow))
WorksheetFunction.Sum (Range("AB2:AB" & DLastRow))
Range("AB" & DLastRow + 1) > WorksheetFunction.Sum(Range("AB2:AB" & DLastRow))
WorksheetFunction.Sum (Range("AC2:AC" & DLastRow))
Range("AC" & DLastRow + 1) > WorksheetFunction.Sum(Range("AC2:AC" & DLastRow))
WorksheetFunction.Sum (Range("AE2:AE" & DLastRow))
Range("AE" & DLastRow + 1) > WorksheetFunction.Sum(Range("AE2:AE" & DLastRow))

Merci d'avance
Eric


Avatar
j
pas tout compris ce code, mais une idée serait de faire un truc du genre
(pas testé)

tabl=array("h","t","u","z"....)
for num=0 to ubound(tabl)
Range(tabl(num) & DLastRow + 1) = WorksheetFunction.Sum(Range(tabl(num) &
"2:" & tabl(num) & DLastRow))
next num


http://jacxl.free.fr



a écrit dans le message de news:

Bonjour,
Je constate que je répète 6 fois la même chose, Y a-t-il moyen de
faire plus simple ?
DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"
WorksheetFunction.Sum (Range("T2:T" & DLastRow))
Range("T" & DLastRow + 1) = WorksheetFunction.Sum(Range("T2:T"
& DLastRow))
WorksheetFunction.Sum (Range("U2:U" & DLastRow))
Range("U" & DLastRow + 1) = WorksheetFunction.Sum(Range("U2:U"
& DLastRow))
WorksheetFunction.Sum (Range("Z2:Z" & DLastRow))
Range("Z" & DLastRow + 1) = WorksheetFunction.Sum(Range("Z2:Z"
& DLastRow))
WorksheetFunction.Sum (Range("AB2:AB" & DLastRow))
Range("AB" & DLastRow + 1) WorksheetFunction.Sum(Range("AB2:AB" & DLastRow))
WorksheetFunction.Sum (Range("AC2:AC" & DLastRow))
Range("AC" & DLastRow + 1) WorksheetFunction.Sum(Range("AC2:AC" & DLastRow))
WorksheetFunction.Sum (Range("AE2:AE" & DLastRow))
Range("AE" & DLastRow + 1) WorksheetFunction.Sum(Range("AE2:AE" & DLastRow))

Merci d'avance
Eric
Avatar
j
toujours pas compris le WorksheetFunction.Sum Range(Cells(2, col(i)),
Cells(DLastRow, col(i)))




"isabelle" a écrit dans le message de news:

bonjour Eric,


DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"

col = Array(20, 21, 26, 28, 29, 30)
For i = 0 To 5
WorksheetFunction.Sum Range(Cells(2, col(i)), Cells(DLastRow,
col(i)))

Cells(DLastRow + 1, col(i)) = WorksheetFunction.Sum(Range(Cells(2,
col(i)), Cells(DLastRow, col(i))))

Next


isabelle

Bonjour,
Je constate que je répète 6 fois la même chose, Y a-t-il moyen de
faire plus simple ?
DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"
WorksheetFunction.Sum (Range("T2:T" & DLastRow))
Range("T" & DLastRow + 1) = WorksheetFunction.Sum(Range("T2:T"
& DLastRow))
WorksheetFunction.Sum (Range("U2:U" & DLastRow))
Range("U" & DLastRow + 1) = WorksheetFunction.Sum(Range("U2:U"
& DLastRow))
WorksheetFunction.Sum (Range("Z2:Z" & DLastRow))
Range("Z" & DLastRow + 1) = WorksheetFunction.Sum(Range("Z2:Z"
& DLastRow))
WorksheetFunction.Sum (Range("AB2:AB" & DLastRow))
Range("AB" & DLastRow + 1) > > WorksheetFunction.Sum(Range("AB2:AB" & DLastRow))
WorksheetFunction.Sum (Range("AC2:AC" & DLastRow))
Range("AC" & DLastRow + 1) > > WorksheetFunction.Sum(Range("AC2:AC" & DLastRow))
WorksheetFunction.Sum (Range("AE2:AE" & DLastRow))
Range("AE" & DLastRow + 1) > > WorksheetFunction.Sum(Range("AE2:AE" & DLastRow))

Merci d'avance
Eric




Avatar
isabelle
bonjour ,

Sub Macro2()
col = Array(20, 21, 26, 28, 29, 31)
DLastRow = 10
For i = 0 To 5
MsgBox Range(Cells(2, col(i)), Cells(DLastRow, col(i))).Address
Next
End Sub


isabelle

toujours pas compris le WorksheetFunction.Sum Range(Cells(2, col(i)),
Cells(DLastRow, col(i)))




"isabelle" a écrit dans le message de news:

bonjour Eric,


DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"

col = Array(20, 21, 26, 28, 29, 30)
For i = 0 To 5
WorksheetFunction.Sum Range(Cells(2, col(i)), Cells(DLastRow,
col(i)))

Cells(DLastRow + 1, col(i)) = WorksheetFunction.Sum(Range(Cells(2,
col(i)), Cells(DLastRow, col(i))))

Next


isabelle

Bonjour,
Je constate que je répète 6 fois la même chose, Y a-t-il moyen de
faire plus simple ?
DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"
WorksheetFunction.Sum (Range("T2:T" & DLastRow))
Range("T" & DLastRow + 1) = WorksheetFunction.Sum(Range("T2:T"
& DLastRow))
WorksheetFunction.Sum (Range("U2:U" & DLastRow))
Range("U" & DLastRow + 1) = WorksheetFunction.Sum(Range("U2:U"
& DLastRow))
WorksheetFunction.Sum (Range("Z2:Z" & DLastRow))
Range("Z" & DLastRow + 1) = WorksheetFunction.Sum(Range("Z2:Z"
& DLastRow))
WorksheetFunction.Sum (Range("AB2:AB" & DLastRow))
Range("AB" & DLastRow + 1) >>> WorksheetFunction.Sum(Range("AB2:AB" & DLastRow))
WorksheetFunction.Sum (Range("AC2:AC" & DLastRow))
Range("AC" & DLastRow + 1) >>> WorksheetFunction.Sum(Range("AC2:AC" & DLastRow))
WorksheetFunction.Sum (Range("AE2:AE" & DLastRow))
Range("AE" & DLastRow + 1) >>> WorksheetFunction.Sum(Range("AE2:AE" & DLastRow))

Merci d'avance
Eric








Avatar
isabelle
ps/ la seule différence c'est que les variables sont numérique au lieu d'être alpha,

isabelle

toujours pas compris le WorksheetFunction.Sum Range(Cells(2, col(i)),
Cells(DLastRow, col(i)))




"isabelle" a écrit dans le message de news:

bonjour Eric,


DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"

col = Array(20, 21, 26, 28, 29, 30)
For i = 0 To 5
WorksheetFunction.Sum Range(Cells(2, col(i)), Cells(DLastRow,
col(i)))

Cells(DLastRow + 1, col(i)) = WorksheetFunction.Sum(Range(Cells(2,
col(i)), Cells(DLastRow, col(i))))

Next


isabelle

Bonjour,
Je constate que je répète 6 fois la même chose, Y a-t-il moyen de
faire plus simple ?
DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"
WorksheetFunction.Sum (Range("T2:T" & DLastRow))
Range("T" & DLastRow + 1) = WorksheetFunction.Sum(Range("T2:T"
& DLastRow))
WorksheetFunction.Sum (Range("U2:U" & DLastRow))
Range("U" & DLastRow + 1) = WorksheetFunction.Sum(Range("U2:U"
& DLastRow))
WorksheetFunction.Sum (Range("Z2:Z" & DLastRow))
Range("Z" & DLastRow + 1) = WorksheetFunction.Sum(Range("Z2:Z"
& DLastRow))
WorksheetFunction.Sum (Range("AB2:AB" & DLastRow))
Range("AB" & DLastRow + 1) >>> WorksheetFunction.Sum(Range("AB2:AB" & DLastRow))
WorksheetFunction.Sum (Range("AC2:AC" & DLastRow))
Range("AC" & DLastRow + 1) >>> WorksheetFunction.Sum(Range("AC2:AC" & DLastRow))
WorksheetFunction.Sum (Range("AE2:AE" & DLastRow))
Range("AE" & DLastRow + 1) >>> WorksheetFunction.Sum(Range("AE2:AE" & DLastRow))

Merci d'avance
Eric








Avatar
j
voui voui, Isabelle, ça j'avais bien compris, ce que je ne comprends pas
c'est à quoi sert la ligne
Worksheetfunction.Sum Range(...)
ça calcule la somme de ce qui est dans la plage, ok, mais ça en fait quoi
après ???




"isabelle" a écrit dans le message de news:

ps/ la seule différence c'est que les variables sont numérique au lieu
d'être alpha,


isabelle

toujours pas compris le WorksheetFunction.Sum Range(Cells(2,
col(i)),


Cells(DLastRow, col(i)))




"isabelle" a écrit dans le message de news:

bonjour Eric,


DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"

col = Array(20, 21, 26, 28, 29, 30)
For i = 0 To 5
WorksheetFunction.Sum Range(Cells(2, col(i)), Cells(DLastRow,
col(i)))

Cells(DLastRow + 1, col(i)) = WorksheetFunction.Sum(Range(Cells(2,
col(i)), Cells(DLastRow, col(i))))

Next


isabelle

Bonjour,
Je constate que je répète 6 fois la même chose, Y a-t-il moyen de
faire plus simple ?
DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"
WorksheetFunction.Sum (Range("T2:T" & DLastRow))
Range("T" & DLastRow + 1) = WorksheetFunction.Sum(Range("T2:T"
& DLastRow))
WorksheetFunction.Sum (Range("U2:U" & DLastRow))
Range("U" & DLastRow + 1) = WorksheetFunction.Sum(Range("U2:U"
& DLastRow))
WorksheetFunction.Sum (Range("Z2:Z" & DLastRow))
Range("Z" & DLastRow + 1) = WorksheetFunction.Sum(Range("Z2:Z"
& DLastRow))
WorksheetFunction.Sum (Range("AB2:AB" & DLastRow))
Range("AB" & DLastRow + 1) > >>> WorksheetFunction.Sum(Range("AB2:AB" & DLastRow))
WorksheetFunction.Sum (Range("AC2:AC" & DLastRow))
Range("AC" & DLastRow + 1) > >>> WorksheetFunction.Sum(Range("AC2:AC" & DLastRow))
WorksheetFunction.Sum (Range("AE2:AE" & DLastRow))
Range("AE" & DLastRow + 1) > >>> WorksheetFunction.Sum(Range("AE2:AE" & DLastRow))

Merci d'avance
Eric










Avatar
isabelle
j'suis d'avis que Eric n'a pas tout mit le code !?
isabelle

voui voui, Isabelle, ça j'avais bien compris, ce que je ne comprends pas
c'est à quoi sert la ligne
Worksheetfunction.Sum Range(...)
ça calcule la somme de ce qui est dans la plage, ok, mais ça en fait quoi
après ???




"isabelle" a écrit dans le message de news:

ps/ la seule différence c'est que les variables sont numérique au lieu
d'être alpha,

isabelle

toujours pas compris le WorksheetFunction.Sum Range(Cells(2,
col(i)),


Cells(DLastRow, col(i)))




"isabelle" a écrit dans le message de news:

bonjour Eric,


DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"

col = Array(20, 21, 26, 28, 29, 30)
For i = 0 To 5
WorksheetFunction.Sum Range(Cells(2, col(i)), Cells(DLastRow,
col(i)))

Cells(DLastRow + 1, col(i)) = WorksheetFunction.Sum(Range(Cells(2,
col(i)), Cells(DLastRow, col(i))))

Next


isabelle

Bonjour,
Je constate que je répète 6 fois la même chose, Y a-t-il moyen de
faire plus simple ?
DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"
WorksheetFunction.Sum (Range("T2:T" & DLastRow))
Range("T" & DLastRow + 1) = WorksheetFunction.Sum(Range("T2:T"
& DLastRow))
WorksheetFunction.Sum (Range("U2:U" & DLastRow))
Range("U" & DLastRow + 1) = WorksheetFunction.Sum(Range("U2:U"
& DLastRow))
WorksheetFunction.Sum (Range("Z2:Z" & DLastRow))
Range("Z" & DLastRow + 1) = WorksheetFunction.Sum(Range("Z2:Z"
& DLastRow))
WorksheetFunction.Sum (Range("AB2:AB" & DLastRow))
Range("AB" & DLastRow + 1) >>>>> WorksheetFunction.Sum(Range("AB2:AB" & DLastRow))
WorksheetFunction.Sum (Range("AC2:AC" & DLastRow))
Range("AC" & DLastRow + 1) >>>>> WorksheetFunction.Sum(Range("AC2:AC" & DLastRow))
WorksheetFunction.Sum (Range("AE2:AE" & DLastRow))
Range("AE" & DLastRow + 1) >>>>> WorksheetFunction.Sum(Range("AE2:AE" & DLastRow))

Merci d'avance
Eric













Avatar
eric
Il me semble que le code est clair, ça met la somme à la fin de la
colonne...
Range("T" & DLastRow + 1) = WorksheetFunction.Sum(Range("T2:T" &
DLastRow))


"isabelle" a écrit dans le message de news:
%
j'suis d'avis que Eric n'a pas tout mit le code !?
isabelle

voui voui, Isabelle, ça j'avais bien compris, ce que je ne comprends
pas
c'est à quoi sert la ligne
Worksheetfunction.Sum Range(...)
ça calcule la somme de ce qui est dans la plage, ok, mais ça en fait
quoi
après ???




Avatar
j
bah, j'avais ça sur le premier message :

DLastRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
Range("H" & DLastRow + 1) = "SOMME"
WorksheetFunction.Sum (Range("T2:T" & DLastRow))
Range("T" & DLastRow + 1) = WorksheetFunction.Sum(Range("T2:T" &
DLastRow))
WorksheetFunction.Sum (Range("U2:U" & DLastRow))
Range("U" & DLastRow + 1) = WorksheetFunction.Sum(Range("U2:U" &
DLastRow))
WorksheetFunction.Sum (Range("Z2:Z" & DLastRow))

doit quand même y avoir des trucs en trop...


"eric" a écrit dans le message de news:
47c862e8$0$21150$
Il me semble que le code est clair, ça met la somme à la fin de la
colonne...
Range("T" & DLastRow + 1) = WorksheetFunction.Sum(Range("T2:T" &
DLastRow))


"isabelle" a écrit dans le message de news:
%
j'suis d'avis que Eric n'a pas tout mit le code !?
isabelle

voui voui, Isabelle, ça j'avais bien compris, ce que je ne comprends
pas
c'est à quoi sert la ligne
Worksheetfunction.Sum Range(...)
ça calcule la somme de ce qui est dans la plage, ok, mais ça en fait
quoi
après ???