简体   繁体   English

在 VBA Excel 中,根据特定条件从用户表单传递值的代码

[英]In VBA Excel, code to pass value from userform based on certain criteria

I need some help for a vba code.对于 vba 代码,我需要一些帮助。

Data is on the same worksheet.数据在同一个工作表上。

I created a userform that contains a combobox and a text box.我创建了一个包含 combobox 和文本框的用户表单。 The values in the combobox are names stored in sheet1.range("A1:A300"). combobox 中的值是存储在 sheet1.range("A1:A300") 中的名称。 The user enters a phone number in the textbox.用户在文本框中输入电话号码。

I struggle creating a code where I could pass the textbox value next to the name choosen by the user in the combobox.我很难创建一个代码,我可以在 combobox 中用户选择的名称旁边传递文本框值。 The textbox value would be stored in column B.文本框值将存储在 B 列中。

Thanks for the help.谢谢您的帮助。

Maybe something like this?也许是这样的?

Private Sub TextBox1_Change()
Set Rng = Range("A1:A300")
Set c = Rng.Find(ListBox1.Value, lookat:=xlWhole)
c.Offset(0, 1).Value = TextBox1.Value
End Sub

Private Sub UserForm_Initialize()
Set Rng = Range("A1:A300")
ListBox1.List = Application.Transpose(Rng)
End Sub

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel - VBA:将变量从 Sub 传递到 Userform - Excel - VBA : pass variable from Sub to Userform 将值从自动过滤器传递到VBA中的combox用户窗体 - Pass the value from autofilter to a combox userform in vba EXCEL VBA USERFORM-如果选择了某些组合框,则将值设为负 - EXCEL VBA USERFORM - Make value negative if certain combobox selected Pass Criteria 从 Excel 到 VBA function call - Pass Criteria from Excel to VBA function call Excel中的VBA:根据输入到用户表单中的信息更改文件名的代码? - VBA in Excel: Code to change a filename based on information entered into a userform? 基于 VBA 中的多个条件使用用户表单更新列表 - Update list with userform based on multiple criteria in VBA Excel VBA:将Click事件中的Target变量传递给用户窗体 - Excel VBA: Pass `Target` Variable from Click Event to Userform VBA - 根据用户表单条件插入两个新行,并复制单元格范围的 Excel 公式 - VBA - Insert two new rows based on Userform criteria and also copying the excel formula of a cell range Excel VBA根据多个用户窗体组合框中的多列数据匹配条件选择一行 - Excel VBA Select a row based on its multi-column data matching criteria in multiple userform comboboxes VBA Excel - 如果列中的某个值符合我的条件,则显示一条消息 - VBA Excel - If a certain value in the column matches my criteria then display a message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM