【发布时间】:2017-12-04 07:45:03
【问题描述】:
我是 VBA 新手,正在使用以下 sn-p 使用 vlookup 函数填充一系列单元格:
With wbk1.Sheets("classes")
.Range("AA2:AA" & .Range("C" & .Rows.Count).End(xlUp).Row).Formula = "=VLOOKUP(C2,lookup!$A$2:$B$14,2,FALSE)" 'Actual vlookup
为了使这个动态,我想用动态引用替换.Range("AA2:AA" & .Range("C" & .Rows.Count) 部分(在我的例子中是同一张表中的第一个空列)。
首先,我找到了第一个带有这个单行符的空列:
first_empty_column = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
但是,当我这样做时
With wbk1.Sheets("classes")
.Range(ws.Cells(1, first_empty_column) & .Range("C" & .Rows.Count).End(xlUp).Row).Formula = "=VLOOKUP(C2,lookup!$A$2:$B$14,2,FALSE)" 'Actual vlookup
我收到“运行时错误‘1004’:应用程序定义的对象定义的错误。
在这种情况下动态定义硬编码范围的语法是什么?
【问题讨论】: