2017-03-01 26 views
0

我有一份每週報告,我需要運行的地方可以獲得與不同團隊相關的用戶列表以及每個給定任務的完成時間。我需要向每個團隊報告任務完成的平均週期時間。VBA宏按團隊分組和報告平均值

task Name Team Cycle time 
7701 john A   5 
7825 tom  A   2 
6945 terri C   7 
7036 jane B   6 
6946 tim  B   9 
6899 john A   4 
7135 jim  C   6 
7805 jim  C   2 
9405 terri C   8 
6209 jason B   2 
7508 derek A   4 
8305 derek A   5 
8426 jane B   6 
3256 juan C   7 

任務,人員和團隊的數量將是動態的

我的想法是由團隊以某種方式拆散數據然後從那裏得到的平均週期時間,但我不知道如何實現那。有誰知道一個VBA命令來卸載數據?

謝謝你的任何想法,你可能都有。

+1

'= averageif(C:C,「A」,D:D)'應該爲團隊A做訣竅。只要得到一個明確的團隊名單,將「A」更改爲任何單元格持有團隊字母你正在平均,然後複製你的公式來覆蓋所有的球隊。 – JNevill

+2

樞軸表將做到這一點。 –

+0

請發佈您的代碼到目前爲止,以專注於什麼不工作,而不是爲您創建一個完整的解決方案。 –

回答

0
Sub macro1() 
Dim lastRow As Long, lastRow2 As Long, myArray() As Variant, longNum As Long 
Dim total As Long, rowNumb As Long, tallyCount As Long 

'************************************************************************** 
' This macro uses arrays because it is quicker than ranges 
' However it does paste an array to an out of the way place at columns(zw to zz) 
' I did this to incorporate a speedy removeduplicates so we would have 
' a single list of names 

' Then it siphons through the arrays to get totals for each member and 
' their averages. 
' 
' It assumes your data is in columns a through d and puts 
' Memebr Name in Column E 
' Member total in column F 
' Member Average in column G 

lastRow = Range("A65536").End(xlUp).Row 
myArray = Range("A1:D" & lastRow) 
Range("ZW1:ZZ" & lastRow) = myArray 
Columns(Range("ZX" & 1).Column).Select 
Range("ZX1:ZX" & lastRow).RemoveDuplicates Columns:=Array(1), Header:=xlYes 
lastRow2 = Range("ZX65536").End(xlUp).Row 
nameArray = Range("ZX2:ZX" & lastRow2) 
Range("ZW1:ZZ" & lastRow).ClearContents 
Range("A1").Select 
rowNumb = 2 
For i = LBound(nameArray) To UBound(nameArray) 
    Debug.Print nameArray(i, 1) 
Next i 

For i = LBound(nameArray) To UBound(nameArray) 
    total = 0 
    For j = LBound(myArray) To UBound(myArray) 
     If myArray(j, 2) = nameArray(i, 1) Then 
      tallyCount = tallyCount + 1 
      total = total + myArray(j, 4) 
     End If 
    Next j 
     If total <> 0 Then 
      Range("E" & rowNumb) = nameArray(i, 1) 
      Range("F" & rowNumb) = total 
      Range("G" & rowNumb) = total/tallyCount 
      rowNumb = rowNumb + 1 
      tallyCount = 0 
     End If 
Next i 
End Sub