Sub Reflector()
Dim ws As Worksheet
Set ws = Worksheets("RAWCALC")
Dim i As Integer
Dim endRow As Integer
endRow = ws.Cells(ws.Rows.Count, "W").End(xlUp).Row
For i = 2 To endRow
If ws.Range("W" & i).Value = "1" Or ws.Range("W" & i).Value = "-1" Then
With ws.Range("G" & i)
.FormulaR1C1 = "=IFERROR(AVERAGEIF(INDIRECT(RC1&""!""&""5:5""),IF(RC10=""Good"",""Blue"",""Red""),OFFSET(INDIRECT(RC1&""!""&""5:5""),ROW(A1),0)),"""")"
'I would like the RC1, RC2, and RC10, A1 to continue to iterate when I autofill down, but I want ROW(A1)to reset itself back to A1 or 1 when a new condition is hit
.AutoFill Destination:=ws.Range(ws.Range("G" & i), ws.Range("G" & endRow))
End With
End If
Next i
End Sub
在W列中,我有1,0或-1作为值。当它达到-1或1时,我希望它在偏移函数中将行计数重置为1。但是如果它是0我希望它继续正常迭代。 G列是我将插入公式的地方。列RC1和RC10将分别指向哪个文件和附加条件。
我真正想要的是一种有条件地重置参考迭代的一部分的方法。提前谢谢!
如果这看起来与昨天看到的问题类似,我为XY问题道歉。
编辑(我想要的公式):所以我希望带有$的那些继续迭代,无论它拖动到自动填充的所有行,但是当它击中1时ROW(A1)重置回ROW(A1)或-1。
=IFERROR(AVERAGEIF(INDIRECT($A2&"!"&"5:5"),IF($J2="Good","Blue","Red"),OFFSET(INDIRECT($A2&"!"&"5:5"),ROW(A1),0)),"")
P.S。任何优化都会有所帮助......这很可能是10000多行