|
昨天在网上找了好久的多条件汇总求和的教程,结果都是用的字典,而我一点也不懂。
早上上班摸鱼搞了个for循环加if判断,也不知道有什么样的缺点!
发到论坛想请哪位大侠看到后给指点一二,或者提供下其它的方法。
真心感谢!
Sub 成绩汇总()
Dim arr, myarr, j As Byte, r As Byte
myarr = Range("b1").CurrentRegion
arr = Range("h1").CurrentRegion
For r = 2 To UBound(arr)
For j = 2 To UBound(myarr)
If myarr(j, 1) = arr(r, 1) And myarr(j, 2) = arr(r, 2) And arr(r, 3) = "" Then
arr(r, 3) = myarr(j, 3)
Else
If myarr(j, 1) = arr(r, 1) And myarr(j, 2) = arr(r, 2) And arr(r, 3) <> "" Then
arr(r, 3) = arr(r, 3) + myarr(j, 3)
End If
End If
Next j
Next r
If Range("j2") = "" Then
Range("h1:j" & UBound(arr)) = arr
End If
End Sub
|
|