2017-01-06 348 views
-5

我需要計算以下代碼的百分比。使用VBA計算百分比

單元格AE43給出總計數。

單元AE51給出有效計數。

單元格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 
+2

不知道什麼是你想要做 – Hiten004

回答

0

如何:

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

+0

如何實現這一分多細胞,而不對每個細胞創建單獨的子? –

+0

@walterwhile你可以編程一個循環來覆蓋一組*三元組*,每個{r1,r2,r3} –