application.worksheetfunction.vlookup错误1004?
我在我的代码中有一个debugging,但我不明白为什么会发生,请你审查代码,看看我搞砸了? 注意错误debugging正在ActiveCell.FormulaR1C1线上发生。
'ENRICHMENT CODE FOR VARIOUS TITLES For Each wbtitle In wbrange sThisWorkTitle = wbtitle sThisWorkColumnNum = wbtitle.Column sThisWorkColumnNam = Split(Cells(, sThisWorkColumnNum).Address, "$")(1) 'identifying CASH RADICAL COLUMN LETTER If sThisWorkTitle = "Account Cash Radical" Then scashradicalcolumnnam = Split(Cells(, sThisWorkColumnNum).Address, "$")(1) Else 'do nothing End If ''' CASH RELATED? If sThisWorkTitle = "Cash Related?" Then wbtitle.Select Range(sThisWorkColumnNam + gspstart).Select ActiveCell.FormulaR1C1 = Application.WorksheetFunction.VLookup(Range(scashradicalcolumnnam & ActiveCell.Row), Range(scashradicalcolumnnam & immsstart & ":" & scashradicalcolumnnam & immsfinal), 1, False) ActiveCell.AutoFill Range(ActiveCell.Address, Cells(gspfinal)) Columns(sThisWorkTitle).Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues Else 'do nothing End If
斯科特已经突出了问题线。
您可以尝试修改,以便将实际公式插入到单元格中。
所以,而不是以下:
ActiveCell.FormulaR1C1 = _ Application.WorksheetFunction.VLookup( & _ Range(scashradicalcolumnnam & ActiveCell.Row) & _ , Range(scashradicalcolumnnam & immsstart & ":" & scashradicalcolumnnam & immsfinal), 1, False)
就像是:
ActiveCell = "=vlookup(" & scashradicalcolumnnam & ActiveCell.Row & _ "," & scashradicalcolumnnam & immsstart & ":" & _ scashradicalcolumnnam & immsfinal & _ ", 1, False)"