application.worksheetfunction.vlookup错误1004?

时间:2016-02-17 15:07:52

标签: excel vba excel-vba

我的代码中有调试,但我无法弄清楚为什么会发生这种情况,请您查看代码并查看我搞砸了哪里?请注意,错误调试发生在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

1 个答案:

答案 0 :(得分:1)

斯科特强调了这个问题。

您可以尝试修改,以便将实际公式插入到单元格中 所以而不是以下内容:

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