How to disable the Drop down list in excel?

时间:2019-04-08 14:04:59

标签: excel vba excel-formula

I am having two drop down list C1 and D1 where C1 contains Country list. D1 should act like a drop down only when UAE and VN selected in C1 list

If I select the country other than UAE and VN the D1 act as a normal cell instead of Drop down.

I am unable to disable the Drop down when I select country other countries than UAE and VN, D1 still act as Drop down list

Sub excelCode()

Dim myValue As Variant


  myValue = ThisWorkbook.Worksheets("Sheet1").Range("C1").Value

  If myValue = "UAE" Or myValue = "VN" Then

  ActiveSheet.DropDowns("D1").Enabled = True

    Else

     ActiveSheet.DropDowns("D1").Enabled = False

  End If

End Sub

1 个答案:

答案 0 :(得分:0)

下面的代码将为only work on ActiveX List Boxes。由于您的描述使用“ US”和“ UAE”值,并且您的代码使用“ UAE”和“ VN”值,因此我选择使用您的代码值,因此可以进行更改以满足您的需求。 Place the code in your worksheet module,根据需要更改工作表编号。 ListBox2 will only be enabled当选择两个值中的任何一个时;如果选择了其他任何值,则ListBox2 will be disabled

Private Sub ListBox1_Click()
'You must use ActiveX Control List Box
    With Sheet1.ListBox1
            If .Value = "UAE" Or .Value = "VN" Then
                Sheet1.ListBox2.Enabled = True

            Else: Sheet1.ListBox2.Enabled = False

            End If
    End With
End Sub