2014-01-20 33 views
0

我目前正在循环中使用包含以下条件的循环。在循环内引用公式中的段时VBA破坏

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”。有谁知道为什么会发生这种情况吗?

回答

0

您混合了.Formula.FormulaR1C1属性以及每个属性的正确语法。尝试使用以下线路:

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)" 
+0

非常感谢你,像一个魅力一样工作。 – user3216149