VBA在循环中引用公式中的节时中断
我目前正在使用一个包含以下条件的循环VBA在循环中引用公式中的节时中断,vba,excel,excel-2007,Vba,Excel,Excel 2007,我目前正在使用一个包含以下条件的循环 For Each Cell In Range("A3:A1000").Cells If Cell.Value = "Existing" And IsEmpty(Cell.Offset(0, 7).Value) Then Cell.Offset(0, 7).Value = "X" Cell.Offset(0, 5).Formula = "=VLookup(RC[-1],Customers!R2:T5000,2,FALSE)"
For Each Cell In Range("A3:A1000").Cells
If Cell.Value = "Existing" And IsEmpty(Cell.Offset(0, 7).Value) Then
Cell.Offset(0, 7).Value = "X"
Cell.Offset(0, 5).Formula = "=VLookup(RC[-1],Customers!R2:T5000,2,FALSE)"
Cell.Offset(0, 6).Formula = "=VLookup(RC[-2],Customers!R2:T5000,3,FALSE)"
End If
Next Cell
除了一个例外,只要将公式附加到单元格,第二个值就变成客户$2:$2:'T5000'。有人知道为什么会发生这种情况吗?您混合了
.Formula
和.formula1c1
属性,并为每个属性更正了语法。尝试以下几行:
Cell.Offset(0,5).FormulaR1C1 = "=VLookup(RC[-1],Customers!R2C18:R5000C20,2,FALSE)"
Cell.Offset(0,6).FormulaR1C1 = "=VLookup(RC[-2],Customers!R2C18:R5000C20,3,FALSE)"