|
我想求百分比,不合格数÷总数=百分比,以下有两段: Sub geren1() 结果是不合格数,Sub geren2() 结果是总数,但不知道怎么 怎么把这两段代码调用合并到一起直接出百分比结果,请老师帮忙看看
Sub geren1()
Dim arr, brr, dic As Object, k%
Set dic = CreateObject("Scripting.Dictionary")
arr = Sheets("sheet1").[a2].CurrentRegion
For i = 2 To UBound(arr)
dic(arr(i, 28) & arr(i, 5)) = dic(arr(i, 28) & arr(i, 5)) + arr(i, 16) + arr(i, 17) + arr(i, 18)
Next
brr = Sheets("sheet2").[c1].CurrentRegion
Sheets("sheet2").Range("d3:ah" & UBound(brr)).ClearContents
For j = 3 To UBound(brr)
For k = 4 To 34
If dic.exists(brr(j, 2) & Cells(2, k)) Then
Cells(j, k) = dic(brr(j, 2) & Cells(2, k))
End If
Next k
Next j
End Sub
上面这段结果除以下面这段结果 怎么修改?
Sub geren1()
Dim arr, brr, dic As Object, k%
Set dic = CreateObject("Scripting.Dictionary")
arr = Sheets("sheet1").[a2].CurrentRegion
For i = 2 To UBound(arr)
dic(arr(i, 28) & arr(i, 5)) = dic(arr(i, 28) & arr(i, 5)) + arr(i, 19)
Next
brr = Sheets("sheet2").[c1].CurrentRegion
Sheets("sheet2").Range("d3:ah" & UBound(brr)).ClearContents
For j = 3 To UBound(brr)
For k = 4 To 34
If dic.exists(brr(j, 2) & Cells(2, k)) Then
Cells(j, k) = dic(brr(j, 2) & Cells(2, k))
End If
Next k
Next j
End Sub
实际上我要的结果是:arr(i,16)+arr(i,17)+arr(i,18)除以arr(i,19) 这样循环是单行的相除,需要所有行循环累加完再相除,不知道怎么改 请老师指导一下
|
|