VBA Excel在单元格中显示组合框的结果

VBA Excel在单元格中显示组合框的结果,vba,excel,Vba,Excel,我想在单元格中显示组合框的值。当我选择一个组合框时,它的值应该显示在单元格中。 我的代码不起作用: 删除此行: .Clear 尽量做到这样明确: Private Sub ComboBox1_Change() 'you don't need a loop to add values, use List property Me.ComboBox1.List = Application.Transpose(Sheet3.Range("A1:A15")) 'if you wan

我想在单元格中显示组合框的值。当我选择一个组合框时,它的值应该显示在单元格中。 我的代码不起作用:

删除此行:

.Clear
尽量做到这样明确:

Private Sub ComboBox1_Change()
    'you don't need a loop to add values, use List property
    Me.ComboBox1.List = Application.Transpose(Sheet3.Range("A1:A15"))
    'if you want the data transferred to the sheet that contains the ComboBox, use below
    Me.Range("D1") = Me.ComboBox1.Value
    'if not, use below the commented line
    'Sheet3.Range("D1") = Me.ComboBox1.Value
End Sub
现在唯一的问题是,如何初始化这些值。 首先,您的ComboBox1列表将为空。 您可以尝试使用其他事件来执行此操作。嗯

Private Sub ComboBox1_Change()
    'you don't need a loop to add values, use List property
    Me.ComboBox1.List = Application.Transpose(Sheet3.Range("A1:A15"))
    'if you want the data transferred to the sheet that contains the ComboBox, use below
    Me.Range("D1") = Me.ComboBox1.Value
    'if not, use below the commented line
    'Sheet3.Range("D1") = Me.ComboBox1.Value
End Sub