我正在尝试通过 VBA 使用 xlookup 开发搜索模板。输入单元格将是一串数字,输出将通过 xlookup 公式中记录的宏显示,并将输出复制粘贴为值。单击搜索按钮后,宏将运行并显示 xlookup 结果(14 个单元格/列)。但是,我无法防止文件滞后,因为数据源范围来自一个大(20+MB)文件,该文件保存在共享驱动器中,并且会不时更新。有没有办法可以将路径写为宏中的字符串或其他方式来帮助解决滞后?
这是录制的宏
Sub Search()
'
' Search Macro
' AU Stripe Macro Search
'
'
Range("B6").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2,'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C1,""Merchant Details Not Available"")"
Range("B7").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2,""Merchant Details Not Available"")"
Range("B8").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C3,""Merchant Details Not Available"")"
Range("B9").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C4,""Merchant Details Not Available"")"
Range("B10").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C5,""Merchant Details Not Available"")"
Range("B11").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C6,""Merchant Details Not Available"")"
Range("B12").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C7,""Merchant Details Not Available"")"
Range("B13").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C8,""Merchant Details Not Available"")"
Range("B14").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C9,""Merchant Details Not Available"")"
Range("B15").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C10,""Merchant Details Not Available"")"
Range("B16").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C11,""Merchant Details Not Available"")"
Range("B17").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C12,""Merchant Details Not Available"")"
Range("B18").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C13,""Merchant Details Not Available"")"
Range("B19").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(R4C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C2, 'Z:\Folder\[Master List.xlsx]Sheet1'!C14,""Merchant Details Not Available"")"
Range("B6:B19").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub