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

vba

3 réponses
Avatar
isabelle
salutatous,

pouvez-vous m'aider à trouver l'erreur..

DATE N ABC
2010-05-03 2 b
2010-09-16 4 c
2011-05-02 2 b
2011-09-15 4 c
2011-09-19 3.6 a
2012-05-02 3 b
2012-07-17 10 c
2012-09-12 3.6 a
2012-09-13 4 a
2013-04-29 3 b
2013-07-01 10 c
2013-09-17 4 c
2013-09-19 4 a
2014-09-17 4 c
2015-09-17 4 c

j’essaie d'écrire la formule suivante sur vba

=SOMMEPROD(--(A2:A16>AUJOURDHUI())*(A2:A16<DATE(2012;12;31))*(C2:C16="a")*(B2:B16))
qui retourne 7.6

Sub Macro1()
Dim DateRange As Range, NRange As Range, ABCRange As Range, start_date As Date, end_date As Date, ABC As String, n
Set DateRange = Range("A2:A16")
Set NRange = Range("B2:B16")
Set ABCRange = Range("C2:C16")
start_date = DateSerial(2012, 8, 23)
end_date = DateSerial(2012, 12, 31)
ABC = "a"
n = Evaluate("SumProduct((" & DateRange.Address & " > " & start_date & ") * (" & _
DateRange.Address & " < " & end_date & ") * (" & ABCRange.Address & " = " & ABC & ") * (" & NRange.Address & "))")
End Sub

mais n retourne une valeur d'erreur

alors un grand merci à tous ceux qui se pencheront sur ce problème.
--
isabelle

3 réponses

Avatar
DanielCo
Bonjour,

n = Evaluate("SumProduct((" & DateRange.Address & ">" & start_date &
")*(" & _
DateRange.Address & "<" & end_date & ")*(" & ABCRange.Address & "=""" &
ABC & """)*(" & NRange.Address & "))")

Cordialement.
Daniel


salutatous,

pouvez-vous m'aider à trouver l'erreur..

DATE N ABC
2010-05-03 2 b
2010-09-16 4 c
2011-05-02 2 b
2011-09-15 4 c
2011-09-19 3.6 a
2012-05-02 3 b
2012-07-17 10 c
2012-09-12 3.6 a
2012-09-13 4 a
2013-04-29 3 b
2013-07-01 10 c
2013-09-17 4 c
2013-09-19 4 a
2014-09-17 4 c
2015-09-17 4 c

j’essaie d'écrire la formule suivante sur vba

=SOMMEPROD(--(A2:A16>AUJOURDHUI())*(A2:A16<DATE(2012;12;31))*(C2:C16="a")*(B2:B16))
qui retourne 7.6

Sub Macro1()
Dim DateRange As Range, NRange As Range, ABCRange As Range, start_date As
Date, end_date As Date, ABC As String, n
Set DateRange = Range("A2:A16")
Set NRange = Range("B2:B16")
Set ABCRange = Range("C2:C16")
start_date = DateSerial(2012, 8, 23)
end_date = DateSerial(2012, 12, 31)
ABC = "a"
n = Evaluate("SumProduct((" & DateRange.Address & " > " & start_date & ") *
(" & _
DateRange.Address & " < " & end_date & ") * (" & ABCRange.Address & " = " &
ABC & ") * (" & NRange.Address & "))")
End Sub

mais n retourne une valeur d'erreur

alors un grand merci à tous ceux qui se pencheront sur ce problème.
Avatar
Yopop
Bonjour Isabelle,

j'ai modifié 2 choses dans ta macro ci-dessous:

les triples guillemets pour ABC
ABC = """a"""

et j'ai incorporé le date(yy,mm,dd) dans le sommeprod pour le début et
la fin.

Sub Macro1()
Dim DateRange As Range, NRange As Range, ABCRange As Range, start_date
As Date, end_date As Date, ABC As String, n
Set DateRange = Range("A2:A16")
Set NRange = Range("B2:B16")
Set ABCRange = Range("C2:C16")

start_year = 2012
start_month = 8
start_day = 24

end_year = 2012
end_month = 12
end_day = 31
ABC = """a"""

n = Evaluate("SumProduct((" & _
DateRange.Address & " > date(" & start_year & "," & start_month &
"," & start_day & "))*(" & _
DateRange.Address & " < date(" & end_year & "," & end_month & "," &
end_day & ")) * (" & _
ABCRange.Address & " = " & ABC & ") * (" & NRange.Address & "))")

MsgBox n
End Sub


j-p

Le 24/08/2012 02:36, isabelle a écrit :
salutatous,

pouvez-vous m'aider à trouver l'erreur..

DATE N ABC
2010-05-03 2 b
2010-09-16 4 c
2011-05-02 2 b
2011-09-15 4 c
2011-09-19 3.6 a
2012-05-02 3 b
2012-07-17 10 c
2012-09-12 3.6 a
2012-09-13 4 a
2013-04-29 3 b
2013-07-01 10 c
2013-09-17 4 c
2013-09-19 4 a
2014-09-17 4 c
2015-09-17 4 c

j’essaie d'écrire la formule suivante sur vba

=SOMMEPROD(--(A2:A16>AUJOURDHUI())*(A2:A16<DATE(2012;12;31))*(C2:C16="a")*(B2:B16))

qui retourne 7.6

Sub Macro1()
Dim DateRange As Range, NRange As Range, ABCRange As Range, start_date
As Date, end_date As Date, ABC As String, n
Set DateRange = Range("A2:A16")
Set NRange = Range("B2:B16")
Set ABCRange = Range("C2:C16")
start_date = DateSerial(2012, 8, 23)
end_date = DateSerial(2012, 12, 31)
ABC = "a"
n = Evaluate("SumProduct((" & DateRange.Address & " > " & start_date &
") * (" & _
DateRange.Address & " < " & end_date & ") * (" & ABCRange.Address & " > " & ABC & ") * (" & NRange.Address & "))")
End Sub

mais n retourne une valeur d'erreur

alors un grand merci à tous ceux qui se pencheront sur ce problème.
Avatar
isabelle
merci à vous deux, l'erreur provenait bien des guillemets de texte

j'ai également modifié la déclaration des variables start_date et end_date As Long

--
isabelle



Le 2012-08-23 20:36, isabelle a écrit :
salutatous,

pouvez-vous m'aider à trouver l'erreur..

DATE N ABC
2010-05-03 2 b
2010-09-16 4 c
2011-05-02 2 b
2011-09-15 4 c
2011-09-19 3.6 a
2012-05-02 3 b
2012-07-17 10 c
2012-09-12 3.6 a
2012-09-13 4 a
2013-04-29 3 b
2013-07-01 10 c
2013-09-17 4 c
2013-09-19 4 a
2014-09-17 4 c
2015-09-17 4 c

j’essaie d'écrire la formule suivante sur vba

=SOMMEPROD(--(A2:A16>AUJOURDHUI())*(A2:A16<DATE(2012;12;31))*(C2:C16="a")*(B2:B16))
qui retourne 7.6

Sub Macro1()
Dim DateRange As Range, NRange As Range, ABCRange As Range, start_date As Date, end_date As Date, ABC As String, n
Set DateRange = Range("A2:A16")
Set NRange = Range("B2:B16")
Set ABCRange = Range("C2:C16")
start_date = DateSerial(2012, 8, 23)
end_date = DateSerial(2012, 12, 31)
ABC = "a"
n = Evaluate("SumProduct((" & DateRange.Address & " > " & start_date & ") * (" & _
DateRange.Address & " < " & end_date & ") * (" & ABCRange.Address & " = " & ABC & ") * (" & NRange.Address & "))")
End Sub

mais n retourne une valeur d'erreur

alors un grand merci à tous ceux qui se pencheront sur ce problème.