组合框选择中的问题

时间:2013-04-09 05:04:06

标签: vb.net combobox

我是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

1 个答案:

答案 0 :(得分:0)

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

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