简体   繁体   English

在Excel中添加和编辑与VBA链接的组合框和文本框

[英]Add & Edit combobox and textbox linked with VBA in excel

How to add or edit combo box values directly in following code? 如何在以下代码中直接添加或编辑组合框值? When writing a text in a combo box, show error "worksheetfunction" And I can not add a new code. 在组合框中编写文本时,显示错误“ worksheetfunction”,并且我无法添加新代码。

Private Sub UserForm_Click()
    Dim xRg As Range


Private Sub UserForm_Initialize()
    Set xRg = Worksheets("Sheet1").Range("A2:B8")
    Me.ComboBox1.List = xRg.Columns(1).Value
End Sub


Private Sub ComboBox1_Change()
    Dim xRg As Range
    Set xRg = Worksheets("Sheet1").Range("A2:B8")
    Me.TextBox1.Text = Application.WorksheetFunction _
        .VLookup(Me.ComboBox1.Value, xRg, 2, False)
End Sub

To add new items to a combo box list: 要将新项目添加到组合框列表,请执行以下操作:

In this example, the combo box "ComboAdd" is on a form and is linked to data in "F" column: 在此示例中,组合框“ ComboAdd”在表单上,​​并链接到“ F”列中的数据:

Dim NewValueRange As String NewValueRange = "F" & Range("F1048576").End(xlUp).Row + 1 Range(NewValueRange) = UserForm1.ComboAdd.Value Dim NewValueRange As String NewValueRange =“ F”&Range(“ F1048576”)。End(xlUp).Row + 1 Range(NewValueRange)= UserForm1.ComboAdd.Value

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM