Be careful with this code. You may have to change a value in the testrange
to get the combobox enabled after it has been disabled. also so I used
Combobox1.Text, you can also use Combobox1.value. Not usre if you are
comparing text or numbers.
Sub disablecombbox()
Set testrange = Sheets("sheet1").Range("a1:a10")
found = False
For Each cell In testrange
If cell = ComboBox1.Text Then
found = True
Exit For
End If
Next cell
If found = True Then
ComboBox1.enable = True
Else
ComboBox1.enable = False
End If
Why not change the style property of the combobox from fmStyleDropDownCombo
to fmStyleDropdownList. Then the user has to select from the list which will
of course be the list of acceptable values.
If you want to allow typing into the textbox region, then leave ti as
fmStyleDropDownCombo and and change the MatchRequired property to True.
from help on MatchRequired:
Specifies whether a value entered in the text portion of a ComboBox must
match an entry in the existing list portion of the control. The user can
enter non-matching values, but may not leave the control until a matching
value is entered.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.