Excelnoub
Member
Good day,
I am looking to add some code to the following function provided, somewhere online don't quite remember, but the main idea is there.
The following function will make my comboboxes to search for the Letter that I will manually insert in my combobox.
I need to have the following also but I cannot find a method anywhere. I need that, if I insert, let say , letter A in my combobox, to search my list and filter everything starting with the letter a to be viewed in my combobox. If nothing is inserted in the combobox, then, show everything.
Example of my current code in UserForm:
In a Module:
Now this function will add the name of what you are searching for in the textbox each time you add a letter in the combobox.
I am looking to implement, which I don’t have, a method that if I insert a letter, let’s say “A”, to show in the combobox only the value of text that starts with the letter A.
Another Example is if my list has Apple, Banana, Brian and Jim, then if I add B in my Combobox then Banana will populate automatically but if the drop down selection is selected then the list will only have Banana and Brian.
This list will always change and I have some weird names.
Is this possible to use the above function to implement what is requested?
I am looking to add some code to the following function provided, somewhere online don't quite remember, but the main idea is there.
The following function will make my comboboxes to search for the Letter that I will manually insert in my combobox.
I need to have the following also but I cannot find a method anywhere. I need that, if I insert, let say , letter A in my combobox, to search my list and filter everything starting with the letter a to be viewed in my combobox. If nothing is inserted in the combobox, then, show everything.
Example of my current code in UserForm:
Code:
Private Sub UserForm_Initialize()
Dim LastRow As Long
LastRow = Worksheets("Control").Range("V2").End(xlDown).row
Me.ComboBox1.List = Worksheets("Control").Range("V2:V" & LastRow).Value
End Sub
In a Module:
Code:
Private Declare Function SendMessagebyString Lib _
"user32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long
Private Const LB_FINDSTRINGEXACT = &H1A2
Private Const CB_FINDSTRINGEXACT = &H158
Public Function FindStringinListControl(ListControl As Object, ByVal SearchText As String) As Long
'Input:
'ListControl: List or ComboBox Object
'SearchText: String to Search For
'Returns: ListIndex of Item if found
'or -1 if not found
Dim lHwnd As Long
Dim lMsg As Long
On Error Resume Next
lHwnd = ListControl.hWND
If TypeOf ListControl Is ListBox Then
lMsg = LB_FINDSTRINGEXACT
ElseIf TypeOf ListControl Is ComboBox Then
lMsg = CB_FINDSTRINGEXACT
Else
FindStringinListControl = -1
Exit Function
End If
FindStringinListControl = SendMessagebyString(lHwnd, lMsg, -1, SearchText)
End Function
Now this function will add the name of what you are searching for in the textbox each time you add a letter in the combobox.
I am looking to implement, which I don’t have, a method that if I insert a letter, let’s say “A”, to show in the combobox only the value of text that starts with the letter A.
Another Example is if my list has Apple, Banana, Brian and Jim, then if I add B in my Combobox then Banana will populate automatically but if the drop down selection is selected then the list will only have Banana and Brian.
This list will always change and I have some weird names.
Is this possible to use the above function to implement what is requested?