vba 使用命名范围填充列表框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23534710/
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-08 18:10:30  来源:igfitidea点击:

Populate list box with a named range

excelvbaexcel-vbalistboxnamed-ranges

提问by cazzzac

I'm working on my first ever VBA project, and need a bit of absolute newbie guidance.

我正在做我的第一个 VBA 项目,需要一些绝对的新手指导。

  1. I have a submission form that staff will be using to submit their daily KPIs.
  2. I have a list box control in a user form called "lstName" that employees will use to select their name before submitting the form
  3. Employee names are stored in a named range on "Sheet11" called "EmpName".
  1. 我有一个提交表格,工作人员将使用它来提交他们的每日 KPI。
  2. 我在名为“lstName”的用户表单中有一个列表框控件,员工将在提交表单之前使用它来选择他们的姓名
  3. 员工姓名存储在名为“EmpName”的“Sheet11”上的命名范围内。

I want to direct the list box to draw the list of names from the "EmpName" range on Sheet11; but don't know how I would do this in VBA. I was going to use RowSource to point the list box to the data, but I am lost as to how to do this.

我想指示列表框从 Sheet11 上的“EmpName”范围中绘制名称列表;但不知道我将如何在 VBA 中做到这一点。我打算使用 RowSource 将列表框指向数据,但我不知道如何执行此操作。

Really simple question I know, and it has probably been answered in some way on the site, but since I'm completely new to VBA, the answers were beyond me. If someone could provide a stepped out answer that explains what the code is doing that would be amazing!

我知道一个非常简单的问题,它可能已经在网站上以某种方式得到了回答,但是由于我对 VBA 完全陌生,所以答案超出了我的范围。如果有人可以提供一个明确的答案来解释代码正在做什么,那将是惊人的!

回答by

Select your Userform and your ListBox, turn on Properties Window (View -> Properties or F4)

选择您的用户窗体和列表框,打开属性窗口(查看 -> 属性或 F4)

In the Properties Window navigate to the RowSourceproperty and type Sheet11!EmpName

在属性窗口中导航到RowSource属性并键入Sheet11!EmpName

A simple booexample

一个简单的boo例子

enter image description here

在此处输入图片说明