VBA activecell.formulaR1C1绝对可变

我正在学习我自己的vba,所以提前感谢花时间来阅读这个。 我已经研究了很多,并与我的公式variables卡住vba错误,代码如下:

Dim i As Long Dim j As Long Dim k As Integer Dim iVal As Byte With ActiveSheet iVal = .Cells(.Rows.Count, "A").End(xlUp).Row End With j = 2 k = -1 For i = 3 To iVal j = j+1 k = k-1 Range("L3").Select ActiveCell.FormulaR1C1 = "=IF(R" & i & "C5=R[" & k & "])" 'ActiveCell.FormulaR1C1 = "=+IF(R3C5=R[-2]C,R3C1,"" "")" Selection.AutoFill Destination:=Range("L" & i & ": W" & i), Type:=xlFillDefault 

这正是我想用For语句“自动”做的事情

 Range("L3").Select ActiveCell.FormulaR1C1 = "=+IF(R3C5=R[-2]C,R3C1,"" "")" Selection.AutoFill Destination:=Range("L3:W3"), Type:=xlFillDefault Range("L4").Select ActiveCell.FormulaR1C1 = "=+IF(R4C5=R[-3]C,R4C1,"" "")" Selection.AutoFill Destination:=Range("L4:W4"), Type:=xlFillDefault Range("L5").Select ActiveCell.FormulaR1C1 = "=+IF(R5C5=R[-4]C,R5C1,"" "")" Selection.AutoFill Destination:=Range("L5:W5"), Type:=xlFillDefault Next 

我想我真的很接近,但一定是我想念的一个小细节,谢谢。

尝试这个:

 Range("L" & i & ":W" & i).FormulaR1c1 = "=IF(R" & i & "C5 = R[" & k & "]C,R" & i & "C1,"" "")" 

使用r1c1不需要自动填充。

它看起来像你只是需要:

 Range("L3:W" & iVal).FormulaR1C1 = "=IF(RC5=R1C,RC1,"" "")"