在macros中插入通过formular1c1的查找

第一次海报和新的VBA。 我正在尝试使用.FormulaR1C1填充一个Vlookup到一个单元格的范围,并得到一个错误1004.我几乎在这个确切的代码在我的macros的其他地方,它工作正常,所以我不知道什么是错的。 这可能是一个简单的修复,我只是没有看到它…

这里是代码:

Range("W2").Select Range(Selection, Selection.End(xlDown)).FormulaR1C1 = "=VLOOKUP(RC[-2],$AA$2:$AC$35,3,TRUE)" 

如果你打算使用R1C1,那么所有的引用必须是这种格式。

 Range(Range("W2"), Range("W2").End(xlDown)).FormulaR1C1 = "=VLOOKUP(RC[-2],R2C27:R35C29,3,TRUE)" 

但是,您应该始终将工作表的来源应用于每个范围对象:

 With Worksheets("Sheet1") 'Change to your sheet .Range(.Range("W2"), .Range("W2").End(xlDown)).FormulaR1C1 = "=VLOOKUP(RC[-2],R2C27:R35C29,3,TRUE)" End With