[英]Excel VBA Fill Textbox on Userform from worksheet depending on another textbox input
So i have a Userform,所以我有一个用户表单,
On this UserForm I have a ComboBox (comboDepartment), a TextBox (txtCode), and another TextBox (textDescription).在这个用户窗体上,我有一个 ComboBox (comboDepartment)、一个 TextBox (txtCode) 和另一个 TextBox (textDescription)。 Each ComboBox selection has a sheet.
每个 ComboBox 选项都有一个工作表。 (eg Robo1, Robo2, etc...).
(例如 Robo1、Robo2 等...)。 The worksheets have 2 columns ( Column A = is the Error Code and Column B = is the Error Description)
工作表有 2 列(A 列 = 是错误代码,B 列 = 是错误描述)
Now my question, Depending on (comboDepartment) comboBox selection have it select the proper worksheet (Maybe set it as a varible?).现在我的问题,根据 (comboDepartment) 组合框选择让它选择正确的工作表(也许将其设置为变量?)。
Next user would input an Error Code into (txtCode) TextBox (Just Numbers eg 1,2,3, etc...), after inputing the code I need it to fill in the (textDescription) TextBox from column B from the worksheet depending on the error code the user inputed.下一个用户将在 (txtCode) 文本框中输入错误代码(仅数字,例如 1、2、3 等...),在输入代码后,我需要它填写工作表 B 列中的(文本描述)文本框,具体取决于在用户输入的错误代码上。
Was wondering if this is at all possible?想知道这是否可能?
Thank you in advance!先感谢您!
Collect all sheets by getting their names and add them on your combobox.通过获取它们的名称来收集所有工作表并将它们添加到您的组合框中。 On your
Private sub Userform_Initialize
method:在您的
Private sub Userform_Initialize
方法上:
For each deptSheet in Thisworkbook.Worksheets
comboDepartment.AddItem deptSheet.Name
Next
Create a private variable for your worksheet ( dim deptSheet as Worksheet
) and set the selected value on the combobox.为您的工作表创建一个私有变量(
dim deptSheet as Worksheet
)并在组合框上设置选定的值。 On your Private sub comboDepartment_Change
method:在您的
Private sub comboDepartment_Change
方法上:
set deptSheet = Thisworkbook.Sheets(comboDepartment.Value)
You may now reference the sheet on the selected dropdown by: deptSheet.Range("
...您现在可以通过以下方式引用所选下拉列表中的工作表:
deptSheet.Range("
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.