【问题标题】:Issues in combobox selection组合框选择中的问题
【发布时间】:2013-04-09 05:04:06
【问题描述】:

我是 vba excel 的新手,我已经成功放置了一个依赖于下拉列表选择的条件组合框,我面临的问题是每当我点击组合框中的任何项目时,它都不会出现在点击后的框。

谁能帮我解决这个问题。

谢谢

我使用的代码是:

    Private Sub ComboBox1_DropButtonClick()
ComboBox1.Clear


If Worksheets("Sheet1").Cells(2, 1).Value = "PHE" Then
With ComboBox1

For row = 1 To 1300
.AddItem Sheets("Sheet2").Cells(row, 6)
Next row
End With

End If

If Worksheets("Sheet1").Cells(2, 1).Value = "HSS" Then
With ComboBox1
For row = 2 To 56
.AddItem Sheets("Sheet2").Cells(row, 8)
Next row
End With

End If

If Worksheets("Sheet1").Cells(2, 1).Value = "Decanter" Then
With ComboBox1
For row = 3 To 249
.AddItem Sheets("Sheet2").Cells(row, 9)
Next row
End With

End If

End Sub

【问题讨论】:

    标签: vb.net combobox


    【解决方案1】:

    如果您能够以某种方式解释所选值,也许您可​​以重置组合框的值。这仅适用于正确选择值的情况,只是在组合框中不可见。

    ComboBox1.Value = something
    

    另外,这可能更简洁(在这里写代码,所以可能存在拼写错误)。

    Private Sub ComboBox1_DropButtonClick()
    
    ComboBox1.Clear
    
    Select Case Worksheets("Sheet1").Cells(2, 1).Value
    Case "PHE"
      minrow = 1
      maxrow = 1300
      col = 6
    Case "HSS"
      minrow = 2
      maxrow = 56
      col = 8
    Case "Decanter"
      minrow = 3
      maxrow = 249
      col = 9
    Case Else
      'error handling
    End Select
    
    With ComboBox1
      For row = minrow To maxrow
        .AddItem Sheets("Sheet2").Cells(row, col)
      Next row
    End With
    
    End Sub
    

    【讨论】:

    • 感谢您提供更简洁的代码,但您能告诉我如何将我们“点击”的组合框的值指向 ComboBox1.Value = something
    • 这就是我们如何使我们点击的组合框项目出现在组合框中。请帮忙
    猜你喜欢
    • 2018-06-24
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    相关资源
    最近更新 更多