Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 嵌套IFERROR,VLOOKUP,如果VBA代码+;抄下来_Excel_Vba - Fatal编程技术网

Excel 嵌套IFERROR,VLOOKUP,如果VBA代码+;抄下来

Excel 嵌套IFERROR,VLOOKUP,如果VBA代码+;抄下来,excel,vba,Excel,Vba,我正在尝试创建VBA代码来执行以下公式: =IFERROR(Vlookup(C3,粘贴值!$A:$F,6,0),如果(Q2=“”,“”,Q2)) 我还想把这个公式复制到整个列中 Dim LastRow As Long Range("P:P").Copy Range("Q:Q") LastRow = Range("P2:P" & Rows.Count).End(xlUp).Row Range("P2:P" & LastRow).Formula = Application.Works

我正在尝试创建VBA代码来执行以下公式:
=IFERROR(Vlookup(C3,粘贴值!$A:$F,6,0),如果(Q2=“”,“”,Q2))
我还想把这个公式复制到整个列中

Dim LastRow As Long
Range("P:P").Copy Range("Q:Q")
LastRow = Range("P2:P" & Rows.Count).End(xlUp).Row
Range("P2:P" & LastRow).Formula = Application.WorksheetFunction.IFERROR(VLOOKUP(Range("C2"),Range("TableEmail!A:F"),6,FALSE),IF(Q2="","",C2))

当我尝试此操作时,公式没有向下复制/返回语法错误。

如果要填充公式,它必须是字符串。要使用
Application.WorksheetFunction
返回vba中的值时,只能使用该函数。如果需要使用
.formula
将公式放置在单元格或区域中,则公式是US-EN格式的字符串,字符串中包含任何

With ActiveSheet
    Dim LastRow As Long
    .Range("P:P").Copy .Range("Q:Q")
    LastRow = .Range("P" & Rows.Count).End(xlUp).Row
    .Range("P2:P" & LastRow).Formula = "=IFERROR(VLOOKUP(C2,TableEmail!A:F,6,FALSE),IF(Q2="""","""",C2))"
End With

我不知道你的意思,我是VBA新手。你能详细说明一下吗?嘿,斯科特,我仍然没有让代码正常工作。值没有进入第2行,而是进入第1行,它不能作为公式工作,因为前面没有“=”符号。它也没有复制。还有其他想法吗?@kaytea11请查看最新编辑。BigBen发现了错误。