Hi all, i have a combobox that has a rowsource to a named range.
After the user enters a value, or selects a value from the list, i want to check whether the entered value is within the list of values. If not in the list, i want to warn the user.
So far i have done up till the warning part, where i prompt a messagebox with vbYesNo buttons to ask if the user wants to continue or not.
If user presses no, i want to highlight the text in the combobox.
This is the code for the combobox in the exit event
This is the code in a module to validate the selected/entered value
This doesn't seems to work. When i test this, the text doesn't gets highlighted. Maybe it's because i press the TAB key to get out of the combobox, that's why the text doesn't gets highlighted. I don't know. Any ideas?
Thanks in advance
Shie Boon
excel 2003
After the user enters a value, or selects a value from the list, i want to check whether the entered value is within the list of values. If not in the list, i want to warn the user.
So far i have done up till the warning part, where i prompt a messagebox with vbYesNo buttons to ask if the user wants to continue or not.
If user presses no, i want to highlight the text in the combobox.
This is the code for the combobox in the exit event
Private Sub cbx_ANRDealType_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim response As Boolean
response = ComboBoxValidation(cbx_ANRDealType)
If response = False Then
With cbx_ANRDealType
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End Sub
This is the code in a module to validate the selected/entered value
Function ComboBoxValidation(ByRef ctl As Control) As Boolean
Dim response As Variant
If ctl.ListCount <> 0 And ctl.ListIndex = -1 Then ' If an item is not selected then
response = MsgBox("The data you have entered is not in the current list. Do you still want to proceed?", vbExclamation + vbYesNo, "Data not in list")
If response = vbYes Then
ComboBoxValidation = True
ElseIf response = vbNo Then
ComboBoxValidation = False
End If
End If
End Function
This doesn't seems to work. When i test this, the text doesn't gets highlighted. Maybe it's because i press the TAB key to get out of the combobox, that's why the text doesn't gets highlighted. I don't know. Any ideas?
Thanks in advance
Shie Boon
excel 2003
Last edited: