具有动态范围的Sumproduct Vba阵列

时间:2019-03-26 03:54:47

标签: arrays sumproduct

我需要您在动态范围内使用vba数组的sumproduct的帮助。 我的数据范围为A1:A13(产品),D1:D13(位置),G1:G13(价格),I1:I13(数量)-包括第1行的标题。

enter image description here

注意:我可以将sumproduct函数用于A17:D20范围,并将vba数组用于单个单元格作为B17,C17 ...但是我想学习如何为范围A17:D20设置sumproduct。

我需要使用sumproduct vba数组将数据表计算为A17:A20(描述产品列表)和B16:D16(位置列表)。

选项库1 子测试_2()     昏暗的WF作为工作表功能     昏暗A作为范围,b作为范围,c作为范围,d作为范围,e作为范围,f作为范围

Dim Arr1 As Variant, Arr2 As Variant, Arr3 As Variant, Arr4 As Variant, Arr5 As Variant, Arr6 As Variant
Dim i As Integer
Dim m As Integer
Dim j As Integer
Dim k As Integer



Set WF = Application.WorksheetFunction
Set A = Worksheets("Test2").Range("$D$2:$D$13")
Set b = Worksheets("Test2").Range("$A$2:$A$13")
Set c = Worksheets("Test2").Range("$G$2:$G$13")
Set d = Worksheets("Test2").Range("$I$2:$I$13")
Set e = Worksheets("Test2").Range("$A$17:$A$20")
Set f = Worksheets("Test2").Range("$B$16:$D$16")


Arr1 = WF.Transpose(A)
Arr6 = f.Value

For i = 1 To UBound(Arr1)
For m = 1 To UBound(Arr6, 2)   '==> Location A
'For m = 2 To UBound(Arr6, 2)  '==> Location B
'For m = 3 To UBound(Arr6, 2)  '==> Location C



       ' If Arr1(i) = Arr6(1, m) Then

       If Arr1(i) = Arr6(1, m) Then
        Arr1(i) = 1

        Exit For

    Else
        Arr1(i) = 0

        End If

Next m
Next i

Arr2 = WF.Transpose(b)
Arr5 = WF.Transpose(e)


For k = 1 To UBound(Arr2)
For j = 1 To UBound(Arr5)   '==> Cheese
'For j = 2 To UBound(Arr5)  '==> Fish
'For j = 3 To UBound(Arr5)  '==> Bread
'For j = 4 To UBound(Arr5)  '==> Wine

If Arr2(k) = Arr5(j) Then
Arr2(k) = 1
Exit For

Else
Arr2(k) = 0

End If

Next j
Next k

Arr3 = WF.Transpose(c)
Arr4 = WF.Transpose(d)


Range("B17").Value = WF.SumProduct(Arr1, Arr2, Arr3, Arr4)
'Range("B18").Value = WF.SumProduct(Arr1, Arr2, Arr3, Arr4)

结束子

0 个答案:

没有答案