excel 如何从ComboBox访问值?

ss2ws0br  于 2023-04-07  发布在  其他
关注(0)|答案(1)|浏览(122)

我想知道如何访问组合框的值。我尝试了几种语法可能性,但无法在线找到解决方案。将来我需要两个组合框的值来向表中添加新行。

Sub add_termin()
    
        Dim lastrow As Long
        Dim typ As String
        Dim frist As Date
        Dim tops As String
        
        ThisWorkbook.Activate
        Set diesesworkbook = ActiveWorkbook
        
        lastrow = diesesworkbook.Sheets("Termine").Range("A" & Rows.Count).End(xlUp).Row
        typ = ComboBox1.Column(1).Value
        MsgBox (lastrow)

'Hinzufügen neuer Zeile
    'diesesworkbook.Sheets("Termine").Range("A" & (lastrow + 1)).Value = ComboBox1.Value
    'diesesworkbook.Sheets("Termine").Range("B" & (lastrow + 1)).Value = TestBox1.Value
    'diesesworkbook.Sheets("Termine").Range("C" & (lastrow + 1)).Value = ComboBox2.Value

编辑:
我找到的解决方案是在ComboBox前面添加UserForm

typ = Termineingabe.ComboBox1.Value
iaqfqrcu

iaqfqrcu1#

这只是一个如何获取所选索引的列值的示例

Sub ShowContent()
Dim x As ComboBox
Set x = ActiveSheet.ComboBox1
Debug.Print x.List(x.ListIndex, 0) ' zero based
If x.ColumnCount > 1 Then Debug.Print x.List(x.ListIndex, 1)
End Sub

相关问题