用VBA先判断C列的数字是否一样,如果一样判断A列的代码是否一样,如果C列与A列都一样,将A列与C列分别复制到F与H列,并且把A列与C列相同的B列进行相加,把加起来的数值填入G列。例如:G2=B2+B3+B4+B5+B6,G3=B7+B8+B9+B10。一直加到C列的单元格为空白(没有东西为止)。请大神帮帮忙!万分感谢!
凡是需要实现Countifs或者Sumifs的功能,用字典做再合适不过了
Sub Test()On Error Resume Next
Dim Dic As Object, Stri As String, i As Integer
Set Dic = CreateObject("Scripting.Dictionary")
For i = 1 To Cells(Rows.Count, 1).End(3).Row
If Cells(i, 1) = "" And Cells(i, 3) = "" Then GoTo Nexti:
Stri = Cells(i, 1) & "{*}" & Cells(i, 3)
If Dic.Exists(Stri) Then Dic(Stri) = Dic(Stri) + Cells(i, 2) Else Dic(Stri) = Cells(i, 2)
Nexti:
Next
For i = 1 To Cells(Rows.Count, 6).End(3).Row
Stri = Cells(i, 6) & "{*}" & Cells(i, 8)
Cells(i, 7) = Dic(Stri)
Next
Set Dic = Nothing
End Sub
测试无误
温馨提示:答案为网友推荐,仅供参考
第1个回答 2018-04-30
求和 即可追问
作业的题目,需要用到VBA程序,唉!