excel-vba如何使用列表框从另一个工作表中获取数据[关闭]

问题描述 投票:-1回答:1
我制作了一个表格,显示> 20种股票及其价格--2列。

而且我想通过从新工作表的列表框中选择一个项来逐一显示它们。(因此,如果我单击APPL,则A1将打印APPL,而A2将在该工作表上打印其价格)

我被困在这里。尝试在google中搜索时没有结果-我知道,我的搜索词肯定不够好。

任何帮助将不胜感激。

excel vba listbox
1个回答
0
投票
欢迎使用SO,下次展示您到目前为止所做的尝试...

我认为您可以按照以下步骤操作:

Sub TryMe() On Error Resume Next Dim returnedvalue As String With ActiveSheet.Shapes("Zone combinée 1").ControlFormat returnedvalue = .List(.ListIndex) field1 = Application.VLookup(returnedvalue, ThisWorkbook.Sheets(1).Range("A1:E8"), 2, False) field2 = Application.VLookup(returnedvalue, ThisWorkbook.Sheets(1).Range("A1:E8"), 3, False) field3 = Application.VLookup(returnedvalue, ThisWorkbook.Sheets(1).Range("A1:E8"), 4, False) field4 = Application.VLookup(returnedvalue, ThisWorkbook.Sheets(1).Range("A1:E8"), 5, False) End With ThisWorkbook.Sheets(2).Cells(1, 2).Value = field1 ThisWorkbook.Sheets(2).Cells(1, 3).Value = field2 ThisWorkbook.Sheets(2).Cells(1, 4).Value = field3 ThisWorkbook.Sheets(2).Cells(1, 5).Value = field4 End Sub

第1页:

enter image description here

工作表2中的输出:enter image description here

如何将宏链接到列表框

enter image description here

如何在列表框中添加数据集

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.