Excel 365 ActiveX Textbox for "Search as you type" not working on second monitor

%3CLINGO-SUB%20id%3D%22lingo-sub-2850740%22%20slang%3D%22en-US%22%3EExcel%20365%20ActiveX%20Textbox%20for%20%22Search%20as%20you%20type%22%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2850740%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20created%20a%20search-as-you-type%20searchable%20text%20box%20for%20excel%20Table%20%22Materials%22%20using%20ActiveX%20Textbox%20by%20adding%20a%20VBA%20code%20(i%20have%20provided%20the%20code%20below)%20to%20it.%20I%20have%20two%20issues%20that%20I%20need%20answers%2Fhelp%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20The%20ActiveX%20Textbox%20does%20not%20work%20as%20nothing%20appears%20when%20I%20type%20a%20search%20value.%20When%20I%20hit%20enter%20or%20when%20i%20get%20out%20of%20the%20box%20the%20search%20value%20that%20i%20had%20typed%20shows%20up.%20Note%20that%20if%20I%20have%20the%20excel%20on%20the%20laptop%20monitor%20it%20works%2C%20i.e.%20I%20can%20type%20right%20in%20the%20textbox%20and%20i%20can%20see%20it%20as%20i%20type%3C%2FP%3E%3CP%3E2.%20The%20VBA%20code%20I%20use%20looks%20into%20the%20entire%20table%20that%20has%20multiple%20columns.%20The%20search%20data%20is%20in%20on%20column%20called%20Items%20and%20therefore%20does%20not%20return%20any%20result.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSTRONG%3E--------Beginning%20of%20VBA%20code-------%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3EPrivate%20Sub%20TextBox1_Change()%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3EDim%20xStr%2C%20xName%20As%20String%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EDim%20xWS%20As%20Worksheet%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EDim%20xRg%20As%20Range%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EOn%20Error%20GoTo%20Err01%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EApplication.ScreenUpdating%20%3D%20False%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3ExName%20%3D%20%22Materials%22%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3ExStr%20%3D%20TextBox1.Text%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3ESet%20xWS%20%3D%20ActiveSheet%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3ESet%20xRg%20%3D%20xWS.ListObjects(xName).Range%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EIf%20xStr%20%26lt%3B%26gt%3B%20%22%22%20Then%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3ExRg.AutoFilter%20field%3A%3D1%2C%20Criteria1%3A%3D%22*%22%20%26amp%3B%20xStr%20%26amp%3B%20%22*%22%2C%20Operator%3A%3DxlFilterValues%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EElse%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3ExRg.AutoFilter%20field%3A%3D1%2C%20Operator%3A%3DxlFilterValues%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EEnd%20If%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EErr01%3A%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%3EApplication.ScreenUpdating%20%3D%20True%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3EEnd%20Sub%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSTRONG%3E--------End%20of%20VBA%20code-------%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20all%20in%20advance!%3C%2FP%3E%3CP%3EAl.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2850740%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2851853%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20365%20ActiveX%20Textbox%20for%20%22Search%20as%20you%20type%22%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2851853%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22byundt_0-1634342515063.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F317806iBD93E644405FE535%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22byundt_0-1634342515063.png%22%20alt%3D%22byundt_0-1634342515063.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3ESince%20May%202021%2C%20this%20feature%20(data%20validation%20dropdowns%20filter%20the%20list%20in%20response%20to%20what%20you%20type)%20has%20been%20available%20to%20users%20of%20Microsoft%20Online.%20Just%20save%20the%20file%20on%20OneDrive%20and%20access%20it%20using%20a%20web%20browser.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20it%20comes%20to%20desktop%20Excel%20soon.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2851893%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20365%20ActiveX%20Textbox%20for%20%22Search%20as%20you%20type%22%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2851893%22%20slang%3D%22en-US%22%3EThank%20you%20for%20your%20response.%20But%20I%20don't%20use%20the%20online%20excel%20for%20this.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2858166%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20365%20ActiveX%20Textbox%20for%20%22Search%20as%20you%20type%22%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2858166%22%20slang%3D%22en-US%22%3EAfter%20giving%20it%20a%20try%2C%20I%20see%20that%20it%20does%20not%20answer%20my%20question%3A%20it%20does%20not%20instantly%20filter%20as%20I%20type.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2858331%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20365%20ActiveX%20Textbox%20for%20%22Search%20as%20you%20type%22%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2858331%22%20slang%3D%22en-US%22%3E%3CP%3E%22it%20doesn't%20instantly%20filter%20as%20I%20type%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20may%20have%20to%20wait%20a%20fraction%20of%20a%20second%20for%20the%20web%20connection%20to%20refresh%2C%20but%20the%20selections%20offered%20do%20update%20as%20you%20type.%20I%20tested%20that%20feature%20just%20now%2C%20and%20confirmed%20that%20it%20is%20still%20working%20as%20described%20in%20Microsoft's%20feature%20announcement%20in%20Spring%202021.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWere%20you%20using%20a%20web%20browser%20to%20access%20a%20file%20stored%20on%20OneDrive%3F%20The%20feature%20won't%20work%20if%20you%20use%20desktop%20Excel%20to%20open%20the%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20would%20like%20me%20to%20investigate%20VBA%20solutions%20to%20the%20problem%2C%20please%20post%20a%20sample%20workbook%20showing%20your%20code%20and%20a%20working%20dropdown.%20The%20sample%20workbook%20doesn't%20need%20to%20contain%20anything%20other%20than%20a%20sample%20dropdown%20with%20five%20or%20ten%20choices%20and%20the%20code%20that%20is%20not%20working%20the%20way%20you%20want.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'd%20like%20to%20verify%20that%20the%20code%20is%20installed%20in%20the%20right%20place%2C%20name%20references%20are%20correct%2C%20etc.%20Even%20if%20those%20details%20are%20all%20correct%2C%20there%20may%20be%20a%20different%20event%20that%20might%20provide%20more%20responsiveness%2C.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2861289%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20365%20ActiveX%20Textbox%20for%20%22Search%20as%20you%20type%22%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2861289%22%20slang%3D%22en-US%22%3EThat%20would%20be%20great%20of%20you%20to%20investigate%20the%20problems%20I%20have%20posted%20originally.%20Here%20is%20the%20link%20to%20the%20OneDrive%20folder%20as%20you%20have%20requested.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2F1drv.ms%2Fx%2Fs!Aqv4zBSFNKaymT6dx2W3aOhdfCbX%3Fe%3DSrcI5A%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2F1drv.ms%2Fx%2Fs!Aqv4zBSFNKaymT6dx2W3aOhdfCbX%3Fe%3DSrcI5A%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20in%20advance.%3CBR%20%2F%3EAl.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2863509%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20365%20ActiveX%20Textbox%20for%20%22Search%20as%20you%20type%22%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2863509%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20KeyUp%20event%20sub%20runs%20as%20soon%20as%20you%20release%20the%20key%2C%20so%20it%20should%20give%20you%20snappier%20response.%20I%20commented%20out%20the%20statement%20turning%20screen%20updating%20back%20on%20as%20VBA%20does%20this%20for%20you%20automatically%20when%20it%20returns%20control%20to%20the%20worksheet%20user%20interface.%20Setting%20it%20to%20True%20will%20therefore%20perform%20the%20screen%20update%20twice%2C%20taking%20time%20needlessly%20and%20causing%20a%20screen%20flicker.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EPrivate%20Sub%20TextBox1_KeyUp(ByVal%20KeyCode%20As%20MSForms.ReturnInteger%2C%20ByVal%20Shift%20As%20Integer)%0ADim%20xStr%2C%20xName%20As%20String%0ADim%20xWS%20As%20Worksheet%0ADim%20xRg%20As%20Range%0A%20%20%20%20On%20Error%20GoTo%20Err01%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20xName%20%3D%20%22Materials%22%0A%20%20%20%20xStr%20%3D%20TextBox1.Text%0A%20%20%20%20Set%20xWS%20%3D%20ActiveSheet%0A%20%20%20%20Set%20xRg%20%3D%20xWS.ListObjects(xName).Range%0A%20%20%20%20If%20xStr%20%26lt%3B%26gt%3B%20%22%22%20Then%0A%20%20%20%20%20%20%20%20xRg.AutoFilter%20field%3A%3D1%2C%20Criteria1%3A%3D%22*%22%20%26amp%3B%20xStr%20%26amp%3B%20%22*%22%2C%20Operator%3A%3DxlFilterValues%0A%20%20%20%20Else%0A%20%20%20%20%20%20%20%20xRg.AutoFilter%20field%3A%3D1%2C%20Operator%3A%3DxlFilterValues%0A%20%20%20%20End%20If%0AErr01%3A%0A'Application.ScreenUpdating%20%3D%20True%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EI%20misunderstood%20your%20need%20in%20my%20initial%20response%20suggesting%20using%20Excel%20Online.%20You%20don't%20want%20a%20data%20validation%20list%20to%20filter%20itself%20as%20you%20type%2C%20but%20rather%20an%20Excel%20Table.%20Please%20ignore%20that%20suggestion.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi All,

 

I have created a search-as-you-type searchable text box for excel Table "Materials" using ActiveX Textbox by adding a VBA code (i have provided the code below) to it. I have two issues that I need answers/help:

 

1. The ActiveX Textbox does not work as nothing appears when I type a search value. When I hit enter or when i get out of the box the search value that i had typed shows up. Note that if I have the excel on the laptop monitor it works, i.e. I can type right in the textbox and i can see it as i type

2. The VBA code I use looks into the entire table that has multiple columns. The search data is in on column called Items and therefore does not return any result.

 

--------Beginning of VBA code-------

Private Sub TextBox1_Change()

Dim xStr, xName As String
Dim xWS As Worksheet
Dim xRg As Range
On Error GoTo Err01
Application.ScreenUpdating = False
xName = "Materials"
xStr = TextBox1.Text
Set xWS = ActiveSheet
Set xRg = xWS.ListObjects(xName).Range
If xStr <> "" Then
xRg.AutoFilter field:=1, Criteria1:="*" & xStr & "*", Operator:=xlFilterValues
Else
xRg.AutoFilter field:=1, Operator:=xlFilterValues
End If
Err01:
Application.ScreenUpdating = True

End Sub

--------End of VBA code-------

 

Thank you all in advance!

Al.

 

15 Replies

byundt_0-1634342515063.png

Since May 2021, this feature (data validation dropdowns filter the list in response to what you type) has been available to users of Microsoft Online. Just save the file on OneDrive and access it using a web browser.

 

I hope it comes to desktop Excel soon.

 

Thank you for your response. But I don't use the online excel for this.
After giving it a try, I see that it does not answer my question: it does not instantly filter as I type.

"it doesn't instantly filter as I type"

 

You may have to wait a fraction of a second for the web connection to refresh, but the selections offered do update as you type. I tested that feature just now, and confirmed that it is still working as described in Microsoft's feature announcement in Spring 2021.

 

Were you using a web browser to access a file stored on OneDrive? The feature won't work if you use desktop Excel to open the file.

 

If you would like me to investigate VBA solutions to the problem, please post a sample workbook showing your code and a working dropdown. The sample workbook doesn't need to contain anything other than a sample dropdown with five or ten choices and the code that is not working the way you want.

 

I'd like to verify that the code is installed in the right place, name references are correct, etc. Even if those details are all correct, there may be a different event that might provide more responsiveness,. 

That would be great of you to investigate the problems I have posted originally. Here is the link to the OneDrive folder as you have requested.

https://1drv.ms/x/s!Aqv4zBSFNKaymT6dx2W3aOhdfCbX?e=SrcI5A

Thanks in advance.
Al.

The KeyUp event sub runs as soon as you release the key, so it should give you snappier response. I commented out the statement turning screen updating back on as VBA does this for you automatically when it returns control to the worksheet user interface. Setting it to True will therefore perform the screen update twice, taking time needlessly and causing a screen flicker.

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim xStr, xName As String
Dim xWS As Worksheet
Dim xRg As Range
    On Error GoTo Err01
    Application.ScreenUpdating = False
    xName = "Materials"
    xStr = TextBox1.Text
    Set xWS = ActiveSheet
    Set xRg = xWS.ListObjects(xName).Range
    If xStr <> "" Then
        xRg.AutoFilter field:=1, Criteria1:="*" & xStr & "*", Operator:=xlFilterValues
    Else
        xRg.AutoFilter field:=1, Operator:=xlFilterValues
    End If
Err01:
'Application.ScreenUpdating = True

End Sub

I misunderstood your need in my initial response suggesting using Excel Online. You don't want a data validation list to filter itself as you type, but rather an Excel Table. Please ignore that suggestion.

 

Te search is still not looking in the Items column. For example, if I type "fuse" it returns no result, i.e. it filters out all lines instead of filtering for the lines with fuses.

It wasn't filtering the Items column because the Field index (1) in your code was working on the PO # column instead of Items (2). 

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim xStr, xName As String
Dim xWS As Worksheet
Dim xRg As Range
    Application.ScreenUpdating = False
    xName = "Materials"
    xStr = TextBox1.Text
    Set xWS = ActiveSheet
    Set xRg = xWS.ListObjects(xName).Range
    If xStr <> "" Then
        xRg.AutoFilter field:=2, Criteria1:="*" & xStr & "*", Operator:=xlFilterValues
    Else
        xRg.AutoFilter field:=2, Operator:=xlFilterValues
    End If

End Sub
Great! You helped me to resolve my second original question. Thank you!

I still need help with my first question (below, modified):
1. The ActiveX Textbox does not work on an extended monitor to my laptop as nothing appears when I type a search value. When I hit enter or when i get out of the text box, the search value that i had typed shows up. Note that if I have the excel file on the laptop monitor it works, i.e. I can type right in the textbox and i can see it as i type.

Thanks,
Al.

I suggest setting a "stop" in your code by clicking in the light gray border to the left of the statements. If successful, you should see a large maroon dot in the border.

 

Once the macro is invoked by typing in your textbox, code execution will stop at the statement with the stop. You may then hover over variables to see their value, or execute one statement at a time by hitting F8. If you hit F5, code execution continues until the next stop. You can drag the yellow arrow up and down in the left border to execute different statements (a little known and very useful trick when debugging).

 

You may also display the Immediate window (using the View...Immediate window ribbon item) and execute statements you type there; be sure to click to make the cursor at the right end of the line before hitting Enter. You may display values in the Immediate window by prefixing them with a question mark, e.g. ?xStr 

 

These techniques help you identify the statement that isn't working right, what the problem is (most often a variable without a value or with an error value), how to remedy it, and even verify the fix.

It isn't clear to me what you see in the two different windows when using laptop with an external monitor. Is it two different worksheets? Two views of the same worksheet?

 

I tested by creating a second window to display Sheet1. I sized the windows so one of them displayed just TextBox 1, while the other showed just the Table. When the textbox was in Window 2, I couldn't select it. When the textbox was in WIndow 1, the code shown below worked as desired.

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim xStr As String, xName As String
Dim xRg As Range

Application.ScreenUpdating = False
With TextBox1
    xName = "Materials"
    xStr = .Text
    Set xRg = .Parent.ListObjects(xName).Range
    If xStr <> "" Then
        xRg.AutoFilter Field:=2, Criteria1:="*" & xStr & "*", Operator:=xlFilterValues
    Else
        xRg.AutoFilter Field:=2, Operator:=xlFilterValues
    End If
End With

End Sub
The ActiveX text box works as desired on a main display - it can be the laptop monitor or whichever display is set as the main display when extended monitors are used. In our case, we use 1 or 2 monitors attached to our laptops. In my case it works on my laptop display as I keep the laptop monitor as the main one and when I move the excel file to other two monitors it does not work, i.e. I don't see what I type in the text box.
After further investigation, I found that ActiveX controls (I tested both textbox and combobox) cannot be selected in a secondary window. This behavior occurs in 64-bit Excel 2010, 2013 and Microsoft 365. I don't know if it occurs with 32-bit Excel.

I suspect Microsoft will consider this behavior a "feature" rather than a bug because it had the same annoying behavior in multiple Excel versions. Features don't get fixed.

When you use external monitors, they are displaying content in secondary windows. The primary window remains your laptop.

So you have two good choices: abandon the use of ActiveX controls or else make sure to access them in your laptop display. Many Excel MVPs recommend avoiding ActiveX controls because of their buggy behavior.

@byundtthank you for further investigation. But what is the workaround? Can the same be achieved with other ways, say formula approach?

If you revert to event sub TextBox1_Change, you can trigger it by entering a value in its linked cell even if you cannot enter a value directly in the textbox.

 

Private Sub TextBox1_Change()
Dim xStr As String, xName As String
Dim xRg As Range

Application.ScreenUpdating = False
With TextBox1
    xName = "Materials"
    xStr = .Text
    Set xRg = .Parent.ListObjects(xName).Range
    If xStr <> "" Then
        xRg.AutoFilter Field:=2, Criteria1:="*" & xStr & "*", Operator:=xlFilterValues
    Else
        xRg.AutoFilter Field:=2, Operator:=xlFilterValues
    End If
End With
End Sub