简体   繁体   English

根据另一个文本框输入,工作表中的 Excel VBA 填充用户表单上的文本框

[英]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.

相关问题 VBA Excel - 将用户表单文本框值添加到工作表 - VBA Excel - add userform textbox value to worksheet 如何将信息从用户窗体文本框传递到工作表 activeX 文本框(或标签) vba excel - How to pass information from a userform textbox to a worksheet activeX textbox (or label) in vba excel 将文本从UserForm文本框粘贴到另一个工作表上的ActiveCell对应的单元格 - Paste text from UserForm textbox to corresponding cell to ActiveCell on another Worksheet 使用用户窗体中的文本框的值来激活工作表上的另一个文本框 - Using the value of a textbox in a userform to activate another textbox on a worksheet Excel VBA从用户窗体文本框中设置命令按钮标题 - Excel VBA Set a Commandbutton Caption from a Userform Textbox 当在组合框中选择名称时,VBA 用户表单将文本框.值保存到 Excel 工作表 - VBA Userform to save textbox.Value to excel worksheet when name is selected in combobox Excel 2013 64 位 - VBA 用户表单 - 添加 28 天的文本框日期并显示在另一个文本框中 - Excel 2013 64 bit - VBA Userform - Add 28 days to date of textbox and display in another textbox EXCEL VBA:用户窗体文本框中的科学计数法 - EXCEL VBA: Scientific Notation in a Userform Textbox 验证用户窗体(Excel VBA)上的文本框条目 - Validating textbox entry on Userform (Excel VBA) 用户窗体上的Excel VBA文本框单击事件 - Excel VBA Textbox click event on Userform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM