检查下拉列表中的项目是否被选中?

我试图让VBA显示一个MsgBox,如果Yes在列表框中被选中。 列表框没有任何特定的ID,但是这个代码应该适用于我列中的所有列表框。 有人可以显示他们为什么这是行不通的?

我得到一个对象未​​定义的错误,我的第一个if语句正常工作。

谢谢

 If Target.Column = Range("V1").Column And _ Range("R" & ActiveCell.Row).Value = "" And _ Range("V" & ActiveCell.Row).Value <> "Yes" And _ Range("G" & ActiveCell.Row).Value = "Pending" And _ Range("A" & ActiveCell.Row).Value <> "" Then If ListBox.SelectedIndex = "Yes" Then MsgBox "Are You Sure you want to set-up the supplier on AX?" & vbNewLine & _ "Waiting for Manager Approval & Documents have not been returned!" End If End If 

  If ListBox.SelectedIndex = "Yes" Then 

SelectedIndex返回索引,所以1或4等

如果您想比较实际值,请使用SelectedValue ,如:

  If ListBox.SelectedValue= "Yes" Then