macros表中的macros循环中的Vlookup
我试图计算一个VLookup
“off sheet”(我不想将公式放入单元格中,然后将其作为值进行复制和粘贴 – 而我想要进行计算,然后将结果作为值放入单元格中)
我有一个表格,每个月都会添加数据。 我只想计算新行(空白)的VLookup
。 VLookup
结果应该放在名为“Regionals”的表格的A列中。 表格数组是一个名为“Orgs”的表格,它在另一个名为“PAS”的工作表上。 下面的公式检索我正在查找的结果,如果我直接把它放在工作表(在这个例子中的“空白”是在单元格A174560)。
-
VLookup
发生的主表名为“Table6” - 主表在标题为“TAB”的工作表上
- 列B(查找的值)在桌上标题为“县代码”
=VLOOKUP(B174560,Orgs[[#All],[County]:[Regional]],4,FALSE)
我现在的代码是:
Application.ScreenUpdating = False Application.Calculation = xlCalculationManual For Each cell In Range("Table6[Regionals]").SpecialCells(xlCellTypeBlanks) cell.Value = [Application.WorksheetFunction.VLookup(cells(CELL.row,Worksheets("TAB").Range("Table6[County Codes]").column)),Worksheets("PAS").Range("Orgs[#All]),[County]:[Regional]"),4,false)] Next
代码运行时没有错误,但在空白单元格中放置了一个#VALUE
错误。
我猜测问题在于在表格中使用表名和列名的语法,或者是我尝试在vlookup中使用单元格格式。
尝试:
Dim addr, col As Long With Worksheets("TAB") col = .Range("Table6[County Codes]").column For Each cell In .Range("Table6[Regionals]").SpecialCells(xlCellTypeBlanks).Cells addr = .Cells(cell.Row, col).Address() cell.value = .Evaluate("VLOOKUP(" & addr & _ ",Orgs[[#All],[County]:[Regional]],4,FALSE)") Next End With