0
我想讓我的宏將公式放入特定單元格,其單元格引用是由循環定義的,並且公式數據的範圍(對於STDEV.P)基於關閉循環的進度。到目前爲止我所做的代碼能夠插入一行,我希望添加STDEV,在單元格A(x)中輸入文本「StdDev」,然後選擇該新行中的每個單元格(遞增列)。以上操作的代碼如下所示:Excel中的循環中公式的單元格引用VBA
firstCell = 2
lastCell = 2
initialValue = 84
stepSize = 5
lastRow = Range("A1").End(xlDown).Row
lastColumn = Range("A1").End(xlToRight).Column
For x = 2 To lastRow
cellDifference = Range("B" & (x)).Value - initialValue
If Abs(cellDifference) > 1 Then
lastCell = x - 1
Range("B" & (x)).EntireRow.Insert
Range("A" & (x)) = "StdDev"
For y = 2 To lastColumn
Cells(x, y).Select
Next y
x = x + 1
firstCell = x
initialValue = initialValue + stepSize
End If
Next x
我嘗試使用下面的代碼:
Cells(x, y) = "=STDEV.P(" & Cells(firstCell, y) & ":" & Cells(lastCell, y) & ")"
但是,這給了錯誤,「應用程序定義或對象定義的錯誤」。我需要知道如何將單元格參考值輸入到公式中,但將其作爲依賴於循環的動態範圍。
任何與此有關的幫助將不勝感激。謝謝。
完美無缺。這正是我所需要的。非常感謝你! – H0ckeyfr33k99
如果有人閱讀此內容並卡在公式中,可以參考這些視頻。 https://www.youtube.com/user/xtremeExcel –