来自工作表列的 VBA 多列列表框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13514953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:34:36  来源:igfitidea点击:

VBA Multi-column list box from sheet columns

excelvbalistbox

提问by Chris Gregori

I've got a spreadsheet with two sheets, lets call them Sheet A and Sheet B.

我有一个包含两张工作表的电子表格,我们称它们为工作表 A 和工作表 B。

From Sheet A, I click a button and it opens a form with a listbox. Sheet B has 10 columns of data.

在工作表 A 中,我单击一个按钮,它会打开一个带有列表框的表单。工作表 B 有 10 列数据。

I want to select 3 of these columns contents, (A, B, F).

我想选择这些列内容中的 3 个,(A、B、F)。

And display them in this one listbox in different columns but it just isn't working and can't find the correct way to do this..

并将它们显示在不同列的这个列表框中,但它不起作用并且找不到正确的方法来做到这一点..

This is what I have so far:

这是我到目前为止:

git://gist.github.com/4131461.git

git://gist.github.com/4131461.git

So in the end I want a list box with 3 columns, each populate with the ranges 1-10 from 3 columns..

所以最后我想要一个包含 3 列的列表框,每个列表框填充 3 列的 1-10 范围。

I just started doing VBA and I have no idea how to do this..

我刚开始做 VBA,我不知道如何做到这一点..

Help?

帮助?

回答by InContext

lbData is the listbox, change Sheet2 as appropriate to reference your data. Add the below in the userform:

lbData 是列表框,根据需要更改 Sheet2 以引用您的数据。在用户表单中添加以下内容:

Private Sub UserForm_Initialize()

    With Me.lbData
        .ColumnCount = 3
        .ColumnWidths = "33;33;33"
        .RowSource = Sheet2.Range("A1:C10").Address
    End With

End Sub