使用VBA计算百分比

时间:2017-01-06 16:35:12

标签: excel vba percentage

我需要计算以下代码的百分比。

Cell AE43给出总计数。

Cell AE51给出有效计数。

Cell AE53应该保留%。

Sub WBR()
Dim Count1Criteria As Variant
Dim Count3Criteria As Variant
Dim test As Variant
Dim wf As WorksheetFunction
Set wf = Application.WorksheetFunction

Filter1InSummary = Array(Array("AE4", "Latency", "O:O", "Pass"), _
                         Array("AE51", "TT", "G:G", "Yes"), _
                         Array("AE52", "TT", "G:G", "No"), _
                         Array("AE61", "Reactive", "R:R", "Item"))

Filter3InSummary = Array(Array("AE43", "TT", "I:I", "<>Duplicate TT", _
                                             "G:G", "<>Not Tested", _
                                             "U:U", "Item"))
For Each test In Filter3InSummary
    With Worksheets(test(1))
        Range(test(0)) = wf.CountIfs(.Range(test(2)), test(3), _
                                     .Range(test(4)), test(5), _
                                     .Range(test(6)), test(7))
    End With
    Next

1 个答案:

答案 0 :(得分:2)

怎么样:

Sub dural()
    Dim r1 As Range, r2 As Range, r3 As Range

    Set r1 = Range("AE43")
    Set r2 = Range("AE51")
    Set r3 = Range("AE53")
    If r1.Value <> 0 Then
        r3.Value = r2.Value / r1.Value
    End If
    r3.NumberFormat = "00.0%"
End Sub

enter image description here