如何从组合框访问值?



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

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

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

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

相关内容

  • 没有找到相关文章

最新更新