简体   繁体   English

使用单元格值作为 VLOOKUP 表数组的参考?

[英]Use Cell Value as reference for VLOOKUP table array?

I would like to be able to allow a user to change the file being used as a reference in a VLOOKUP.我希望能够允许用户更改在 VLOOKUP 中用作参考的文件。 All the files being used will have the same array, just different files paths.使用的所有文件都将具有相同的数组,只是文件路径不同。

This is how i think it should operate.这就是我认为它应该运行的方式。

  1. Click macro button that opens file browser.单击打开文件浏览器的宏按钮。
  2. Allow user to choose file.允许用户选择文件。
  3. Paste file path in cell (A1)在单元格 (A1) 中粘贴文件路径
  4. Convert path to include array.将路径转换为包含数组。
  5. In VLOOKUP formula, reference the cell A1 as the 'table array'.在 VLOOKUP 公式中,将单元格 A1 引用为“表格数组”。

I am already able to complete up to step 3. Any idea on how to add the defined array and reference the cell in a VLOOKUP?我已经能够完成第 3 步。关于如何添加定义的数组并在 VLOOKUP 中引用单元格的任何想法?

I would just record doing exactly what you want to do and then replace what you did with a variable that gets assigned, like when you place the path into cell A1.我只会记录你想做的事情,然后用一个被分配的变量替换你所做的事情,比如当你将路径放入单元格 A1 时。 Then just have the macro re-write the appropriate vlookup formula.然后只需让宏重新编写适当的 vlookup 公式即可。

You could also make a formula that would show what you want, and then use vba to copy that and paste values.您还可以制作一个公式来显示您想要的内容,然后使用 vba 复制并粘贴值。 You may then need to find and replace something in the cell(s) to get it to actually convert to a formula.然后,您可能需要查找并替换单元格中的某些内容,以使其实际转换为公式。

Example:例子:

In A1 Put the path (with workbook name, i.e.C:\Users\username\Desktop\Book3.xlsx )
In B1 ="=VLOOKUP(D1,'"&MID(A5,1,FIND("*",SUBSTITUTE(A5,"\","*",LEN(A5)-LEN(SUBSTITUTE(A5,"\","")))))&"["&MID(A5,FIND("*",SUBSTITUTE(A5,"\","*",LEN(A5)-LEN(SUBSTITUTE(A5,"\",""))))+1,100)&"]Sheet1'!B$1:C$4,2,FALSE)"
B1 then looks like this =VLOOKUP(D1,'C:\Users\username\Desktop\[Book3.xlsx]Sheet1'!B$1:C$4,2,FALSE)
Copy B1 to C1 and do a find replace of something, like find Users and replace all with Users.

This is messy, but I use something like this for a tool that needs to update form 30 different files of different sizes based on 6000 rows of array formulas that update of yet another spreadsheet.这很混乱,但我使用类似这样的工具来更新 30 个不同大小的不同文件,该文件基于 6000 行数组公式更新另一个电子表格。 It works well for me, but a bit slow for large files.它对我来说效果很好,但对于大文件来说有点慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM