使用vba粘贴值而不是公式
=IFERROR(VLOOKUP($A6318,'https://-/-/-/-/-/-/-/[-.xlsx]-'!$A:$BO,2,FALSE),"")
我要将答案粘贴到单元格A上!无需使用VBA粘贴公式。
答案 0 :(得分:3)
请注意,我不确定您是否可以完全使用https://
链接作为公式中文件的引用。但是这里有3种解决方案:
您可以使用Application.Evaluate method在VBA中获取公式的结果:
Worksheets("Sheet1").Range("A1").Value = Evaluate("=IFERROR(VLOOKUP($A6318,'https://-/-/-/-/-/-/-/[-.xlsx]-'!$A:$BO,2,FALSE),"""")")
或者使用WorksheetFunction.VLookup method直接在VBA中进行查找。
Dim LookupResult As Variant
On Error Resume Next 'next line throws error if no lookup result is found
LookupResult = Application.WorksheetFunction.VLookup(ThisWorkbook.Sheets("Mysheet").Range("$A6318"), Workbooks("whatever.xlsx").Worksheets("Sheetname").Range("$A:$BO"),2,False)
On Error Goto 0 're-activate error handling
Worksheets("Sheet1").Range("A1").Value = LookupResult
请注意,此处whatever.xlsx
必须已经在Excel中打开,否则将无法工作。因此,您可能需要先临时下载并在Excel中打开它。
您可以粘贴公式并计算。然后复制公式结果并将其粘贴为值。
Worksheets("Sheet1").Range("A1").Formula = "=IFERROR(VLOOKUP($A6318,'https://-/-/-/-/-/-/-/[-.xlsx]-'!$A:$BO,2,FALSE),"""")"
Worksheets("Sheet1").Range("A1").Value = Worksheets("Sheet1").Range("A1").Value