带有多个标准的vlookup,返回的数组插入了ComboBox
有没有一种方法可以使用VBA使用多个标准进行Vlookup,然后将这些返回的值插入ComboBox?对于下表,我想将“马林鱼”作为搜索条件,然后将{rbi,score,abv}插入combobox作为选项。这可能吗?
示例数据:
标识符 | 价值 |
---|---|
海盗 | 得分 |
马林斯 | RBI |
MARLINS | 得分 |
Marlins | ABV |
Pirates | HRS |
Application.WorksheetFunction.VLookup("Marlins", Worksheets("Metadata").Range("A2:B5"), 2, False)
Is there a way to use VBA to Vlookup with multiple criteria and then have those multiple returned values then inserted into a ComboBox? For the table below, I would like to have "Marlins" as the search criteria, and then have {RBI, Score, ABV} inserted into a ComboBox as options. Is this possible?
Example Data:
Identifier | Value |
---|---|
Pirates | Score |
Marlins | RBI |
Marlins | Score |
Marlins | ABV |
Pirates | HRS |
Application.WorksheetFunction.VLookup("Marlins", Worksheets("Metadata").Range("A2:B5"), 2, False)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
填充一个Combobox
一个简单的例子
Populate a ComboBox
A Simple Example
如果您处置VEST的较新的动态阵列功能。 MS365,
您可能会从以下函数
过滤()
filter()
公式字符串(基于帮助函数的结果)代码> makeformula 和帮助函数
makeformula
示例示例调用
足以传递整个数据是足够的 或可选标准,例如“马林鱼”)。
范围为参数(和/
获取(重新)由过滤值分配。
If you dispose of the newer dynamic array features of vers. MS365,
you might profit from the following function
filtered()
Filter()
formula string (based on results of help functionMakeFormula
andHelp function
MakeFormula
Example call
It suffices to pass the entire data range as parameter (and/or an optional criteria, e.g. "Marlins").
Note that you don't need to clear the combobox values as the whole
.List
propertygets (re-)assigned by the filtered values.
使用ActiveX Combobox,并将默认名称作为ComboBox1。
该代码假设您的数据与图像附件中的数据完全相同。
因此,标识符标头位于单元格A1中,其中数据从单元A2开始。
值标头位于单元B1中,其中数据从单元格B2开始。
过程:
它作为可变RG的标识符数据范围。
创建具有价值“马林鱼”的可变暴力。
然后在RG中,它替换所有包含文本“ Marlins”的行中的行,以逻辑true,获取包含“ true”偏移量的单元格(0,1),请执行循环以将每个循环的单元格值作为ComboBox1项目,将真正的价值带回“马林鱼”。
该子必须在数据表处于活动状态的情况下运行。
Use the ActiveX ComboBox, and let the default name as ComboBox1.
The code assumed that your data exactly the same as in your image attachment.
So, the Identifier header is in cell A1 where it's data starts from cell A2.
And the Value header is in cell B1 where it's data starts from cell B2.
The process:
It make a range for the Identifier data as variable rg.
create variable crit with value "Marlins".
Then within the rg, it replace all rows which contains text "Marlins" with logical TRUE, get the range of the cell which contains "TRUE" offset(0,1), do the loop to put each looped cell value as the ComboBox1 item, bring the TRUE value back to "Marlins".
The sub must be run where the sheet of your data is active.