Listbox content base on the keywords in textbox

Hi friends,

I am trying to make my TextBox1 work with my ListBox1 to Filter Search Results.

My set up is a bit strange , but for a good reason.

The Listbox populates from an excel sheet

Next I am trying to search a TextBox1 - and filter the results.

So I can search for what I want but I couldnt find a way to fix that.

The goal is to try and run a macro stored within the document when an item is selected from the listbox, I can do that if I use listindex=0,1,2,3 etc.

I wanted to try and simplify that by only running a macro when the item is selected.

I have wasted away this Sunday.

How can I fix my text box search - there is something missing.

And run a macro only when the item is selected from the listbox - I have googled forever and still no luck :[

I have attached the problematic duo in question - doc and the xl sheet

//1drv.ms/w/s!AvcJQhgRih3LkmNwEln3y9TLE28w

//1drv.ms/x/s!AvcJQhgRih3LkmdloYUSmLRG1NCK

Thank you for your help - I really appreciate it

Cheers Dan :]




Hello Ossie,

Pardon my impetuous ignorance.

After a whole day

I have found something that is similar to what I am trying to achieve.

I meant to explain that I was trying to filter the results so I get all the values with apple in them.

I will put in apple in the TextBox1

Private Sub UserForm_Initialize[] With Me.ListBox1 .AddItem "Apple" .AddItem "Apple" .AddItem "Apple" .AddItem "Apple" .AddItem "Bob" .AddItem "Bill" .AddItem "Mark" .AddItem "Apple" .AddItem "Apple" .AddItem "Bob" .AddItem "Bill" .AddItem "Mark" .AddItem "Apple" .AddItem "Apple" .AddItem "Bob" .AddItem "Bill" .AddItem "Mark" End With End Sub

' How can I get the Listbox to display and filter the results

when I enter a search term into the TextBox1

Private Sub TextBox1_change[] Dim strFilter As String Dim lngIndex As Long strFilter = Me.TextBox1.Text For lngIndex = ListBox1.ListCount - 1 To 0 Step -1 If ListBox1.List[lngIndex, 2] strFilter Then ListBox1.RemoveItem [lngIndex] End If Next End Sub


//www.experts-exchange.com/questions/28960114/Excel-VBA-Real-Time-Search-or-Filtering-in-Listbox.html

I have gone back to basics as suddenly it has catapulted me into listbox land for which I had no idea it was this complex - am i able to simply filter a list box with a search keyword that i put in the text box?

For Example Can I display all the results that have apple in them? in the listbox, I can then make a choice from the various apples.

Cheers Dan :]




Hello Ossie,

May I say thank you so much for your incredible help!

I have been working on this for weeks on and off, becuase there were so many problems connecting word to excel - and im none the wiser.

The problem is I am using word to populate a listbox from excel - so by its very nature it became messy.

Everything I found on listboxes was attached to excel within Excel so that made my newbie job very very hard to begin with :[

But im very stubborn and once I see something that would help me do a job, I just cant give up on my idea. I have always wanted a listbox in word but I could never make it work :[ and filtering was out of the question. But I had an urgent outlook list I needed to put in the excel spreadsheet but I was also using word and this cross app inteference was really amplified yesterday.

I can now use this for a multitude of jobs, oh as well as list some macros to in the listbox. Also I just didnt have the energy to look for a combobox solution as if that would be any better so alas I went back to basics.

But you have solved it now!!!

Yay I am sooo happy

So thank you for your very kind and incredbily awesome help .

Reaally stoked to bits!

Have a Wonderful week now - Ossie [ if thats your name]

I have one shiny new toy the ListBox to set up tomorrow - with lots of lists of names and things and things etc

:]

Cheers Dan :]

Video liên quan

Chủ Đề