Search code examples
excelvbaexceptiondropdown

ControlFormat.Enabled property throwing error


I want to lock a dynamic drop down in VBA, but face an issue while trying to set the Dropdown.ControlFormat.Enabled property.

ddlIsNegative.TopLeftCell.Locked = True
Set lbcf = ddlIsNegative.ControlFormat
If (lbcf.value = 2) Then
    ddlIsNegative.ControlFormat.Enabled = False
End If

While setting ddlIsNegative.ControlFormat.Enabled property, it throws the error

unable to set enabled property of Group Object class


Solution

  • I'm able to resolved this issue by adding additional exceptions.

    Err.Clear
            ddlIsNegative.TopLeftCell.Locked = True
            On Error GoTo errExit
            ddlIsNegative.ControlFormat.Enabled = False
    errExit: