用于启用或禁用ActiveX ComboBox的代码

时间:2015-02-26 16:20:54

标签: excel vba excel-vba

我需要一些实际上用于启用和禁用ActiveX ComboBox的代码的帮助。尝试了下面的代码后,它无法正常工作:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("R2").Value = True Then ComboBox1.Enabled = True
    If Range("R2").Value = False Then ComboBox1.Enabled = False
End Sub  

非常感谢任何帮助或建议。

1 个答案:

答案 0 :(得分:0)

这对你有用

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Range("R2"), Range(Target.address)) Is Nothing Then
        If UCase(Range("R2").Value) = "TRUE" Then ComboBox1.Enabled = True
        If UCase(Range("R2").Value) = "FALSE" Then ComboBox1.Enabled = False
    End If
End Sub