如何遍历我的变量数组进行计数然后进行计算?

时间:2019-01-02 14:54:50

标签: excel vba loops

我已经从主表(Sheet3)在Sheet1中创建了一个唯一项的变体数组列表。现在,我不确定如何复制数组中的每个项目并将其粘贴到A列的sheet4中,并将该项目的计数从B列旁边的“一月”工作表中移除。如果可以,我可以执行一些操作计算。非常感谢您的帮助

我基本上是在尝试建立管理信息统计数据,获取我们管理的项目数,然后计算出按时完成的百分比。

到目前为止,这是我为获取变体数组列表所做的工作。

Sub PopulatingArrayVariable_v3()

Dim myarray() As Variant
Dim DataRange As range
Dim Cell As range
Dim x As Long
Dim iReport As Integer

Dim lastRow As Long

Application.ScreenUpdating = False
Application.DisplayAlerts = False

lastRow = Sheets("Sheet3").range("A" & Rows.Count).End(xlUp).Row

With Sheets("Sheet3")

    .range("D2:D" & lastRow).AdvancedFilter Action:=xlFilterCopy, 
copytorange:=Sheets("Sheet1").range("A1"), Unique:=True

End With

Set DataRange = Sheets("Sheet1").UsedRange


For Each Cell In DataRange.Cells
ReDim Preserve myarray(x)
myarray(x) = Cell.Value
x = x + 1
Next Cell
For x = LBound(myarray) To UBound(myarray)
Debug.Print myarray(x)
Next x

iReport = WorksheetFunction.countif(Sheets("January").range("C6:C100"), 
myarray(6))

Sheets("Sheet4").Activate
range("A2") = myarray(6)
range("B2") = iReport

//do calculation in % and rounded to 0 decimal point

Application.ScreenUpdating = False
Application.DisplayAlerts = False


End Sub

这是我希望茶几看起来像

的示例
Items                   Count
EMT - Pre Production     4
EMT - Pre Production     5
EMT - Production         10
EMT - Post Production    1
EPT - Pre Production     20
EPT - Production         10
EPT - Post Production    5
AIFMD  - Pre Production  25
AIFMD  - Production      12
AIFMD  - Post Production 12

0 个答案:

没有答案