作业帮 > 综合 > 作业

G2=SUMIF(A2:A10000,{"C","G","R","B"},B2:B10000) 这句话在VBA数组中可行

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/17 11:44:59
G2=SUMIF(A2:A10000,{"C","G","R","B"},B2:B10000) 这句话在VBA数组中可行,函数怎么不行了?
请问函数怎么写法,或怎么改写?
Sub t5()
Dim arr
arr = Application.SumIf(Range("a2:a10000"),Array("B","C","G","R"),Range("B2:B10000"))
Range("G2").Resize(4,1) = Application.Transpose(arr)
End Sub
G2=SUMIF(A2:A10000,{
G2=SUMIF(A2:A10000,{"C","G","R","B"},B2:B10000)这个虽然不会错,但是有问题啊,它其实相当于G2=SUMIF(A2:A10000,"C",B2:B10000)
所以在宏里面应该是arr = Application.SumIf(Range("a2:a10000"),"C",Range("B2:B10000")).
如果你要统计=C或G或R或B的总和,应该用这个G2=SUM(SUMIF(A2:A10000,{"C","G","R","B"},B2:B10000))
对应宏里面是arr= Application.Sum(Application.SumIf(Range("a2:a10000"),Array("B","C","G","R"),Range("B2:B10000")))