所以我有一个sub,它传递了3个整数值,它创建了一个包含3个不同公式的数组,然后在excel中的不同单元格中逐个使用。
代码:
Private Sub SOB_Measurements_X(ByVal Position As Integer, ByVal RowNumber As Integer, ByVal ColumnNumber As Integer)
Dim i As Integer
Dim Formula1 As Variant
Dim Start
Start = Array("=AVERAGE(IF(Delta (outer)!B1:CZ1=Test_Summary!E8, Delta (outer)!B", "=AVERAGE(IF(height (inner)!B1:CZ1=Test_Summary!E8, height (inner)!B", "=AVERAGE(IF(height (outer)!B1:CZ1=Test_Summary!E8, height (outer) height!B")
Dim Mid As String: Mid = ":CZ"
Dim End1 As String: End1 = "))"
For i = 0 To UBound(Start, 1)
Formula1 = Start(i) & Position & Mid & Position & End1
Cells(RowNumber + i, ColumnNumber).Select
ActiveCell.FormulaArray = Formula1
Next i
End Sub
数组“Start”中有3个不同的公式,它们存储在变量类型的变量Formula1中。不幸的是,上面的代码给了我一个运行时错误“无法设置范围类的FormulaArray属性”。
感谢您的帮助!