0

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

1 回答 1

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
于 2013-04-09T05:22:48.647 回答