[已解决] EXCEL VBA-数据迭代和行明智功能应用程序

时间:2019-06-18 17:01:23

标签: excel vba

我在执行逐行函数应用程序时遇到麻烦-

说我有一个公式,该公式可以归纳为:

preformance = ( 1 - (Part1(IdealRate)*Part1(PiecesProduced)) ) + ( 1 - (Part2(IdealRate)*Part2(PiecesProduced)) ) + ...etc

如果我有一个与此样式相似的excel电子表格-

Excel Example

我如何将每一行的值发送到更大的数组进行求和-本质上就是工作流程。

#Pseudo Begin#

For Each Row in Rows
(1 -(Part(IdealRate)*Part(PiecesProduced))) -> Send to Array
Next Row

当迭代达到结束范围时

Array.Value = Sum(AllValuesInArray)

我尝试为所需的每一列创建范围,然后创建一个将范围放置在其中的数组-我不尝试任何超出此范围的事情,因为我不知道如何开始

任何帮助将不胜感激!谢谢

编辑#这是一个尝试

Dim GoodQty As Range
Dim PreformanceArray() As Single
Dim Iterator As Long
Set GoodQty = Worksheets("HondaOEE").Range(.Cells(3, 4), .Cells(LastRowH, 4))
Dim RangeLength As Long
RangeLength = Worksheets("HondaOEE").UsedRange.Rows.Count
Dim PValue As Double
ReDim PreformanceArray(1 To 1) As Single

For Iterator = 3 To RangeLength
    PValue = Application.SumProduct(1 - (.Cells(Iterator, 8) * (.Cells(Iterator, 4) + .Cells(Iterator, 5) + .Cells(Iterator, 6))))
    PreformanceArray(UBound(PreformanceArray)) = PValue
    ReDim Preserve PreformanceArray(UBound(PreformanceArray) + 1) As Single
Next Iterator

2 个答案:

答案 0 :(得分:0)

您可以使用10000管理这类复杂的聚合。此功能强大,可以对一系列单元格进行计算,然后对它们求和。在上面的示例中,公式为:

final_destination

答案 1 :(得分:0)

Dim PreformanceArray() As Double
Dim Iterator As Long
Dim RangeLength As Long
RangeLength = Worksheets("HondaOEE").UsedRange.Rows.Count
RangeLength = RangeLength - 1
Dim PValue As Double
ReDim PreformanceArray(1 To 1) As Double

For Iterator = 3 To RangeLength
    PValue = (1 / .Cells(Iterator, 8) * (.Cells(Iterator, 4) + .Cells(Iterator, 5) + .Cells(Iterator, 6)))
    PreformanceArray(UBound(PreformanceArray)) = PValue
    ReDim Preserve PreformanceArray(1 To UBound(PreformanceArray) + 1) As Double
Next Iterator

这是正确的代码,可让我执行所需的操作。