Search data then show results in a list box

kira023

New Member
Joined
Mar 13, 2019
Messages
14
Hi,

I'm currently working on a troubleshooting guide for our team and I've created a userform to be able to search using the 2 combo boxes that are dependent with each other. When clicking the Search button I wanted it to use the information on the 2 combo boxes to find it in a single worksheet where all the data is located (eg. Bot Names = column B and automation name = column C) and then show the troubleshooting guide in column D on a list box which corresponds to the data being searched by the 2 combo boxes.

I don't have an initial code for the search button. If someone can please help me create this that would be helpful.

Thank you
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
How is your data laid out?
Is it anything like


Excel 2013/2016
BCD
2SomersetMendipStreet North
3SomersetMendipStreet West
4SomersetBath and North East SomersetFarmborough
5SomersetBath and North East SomersetWestmoreland
6SomersetBath and North East SomersetTwerton
7SomersetBath and North East SomersetWidcombe
8SomersetSouth SomersetYeovil Central
9SomersetSouth SomersetYeovil East
10SomersetSouth SomersetCary
11SomersetSouth SomersetIvelchester
12SomersetBath and North East SomersetTimsbury
13SomersetBath and North East SomersetWestfield
14SomersetMendipChewton Mendip and Ston Easton
15SomersetMendipColeford and Holcombe
User2


Where col B is combo1 value, col C is combo2 & cold D is what needs to go in the listbox?
 
Upvote 0
Hi fluff,sorry for the late reply.yes that is the same format as my spreadsheet. I just need to know how to do it on the conditions that i wanted.thank you
 
Upvote 0
Ok, how about
Code:
[COLOR=#ff0000]Option Explicit
Dim ufDic As Object
[/COLOR]
Private Sub ComboBox1_Click()
   Me.ComboBox2.Clear
   Me.ListBox1.Clear
   Me.ComboBox2.List = ufDic(Me.ComboBox1.Value).Keys
End Sub

Private Sub ComboBox2_Change()
   Me.ListBox1.Clear
   Me.ListBox1.List = ufDic(Me.ComboBox1.Value)(Me.ComboBox2.Value).Keys
End Sub

Private Sub UserForm_Initialize()
   Dim Cl As Range
   Dim Ws As Worksheet
   
   Set Ws = Sheets("[COLOR=#0000ff]Data[/COLOR]")
   Set ufDic = CreateObject("scripting.dictionary")
   ufDic.CompareMode = 1
   For Each Cl In Ws.Range("B2", Ws.Range("B" & Rows.Count).End(xlUp))
      If Not ufDic.Exists(Cl.Value) Then ufDic.Add Cl.Value, CreateObject("scripting.dictionary")
      If Not ufDic(Cl.Value).Exists(Cl.Offset(, 1).Value) Then ufDic(Cl.Value).Add Cl.Offset(, 1).Value, CreateObject("scripting.dictionary")
      ufDic(Cl.Value)(Cl.Offset(, 1).Value)(Cl.Offset(, 2).Value) = Empty
   Next Cl
   Me.ComboBox1.List = ufDic.Keys
End Sub
The two lines in red must go at the very top of the module, before any code.
Change sheet name in blue to suit.
 
Upvote 0
Hi Fluff,

Thanks for the code. I think it works fine but I wanted to tweak some of it. Is there a way to adjust the text shown on the list box? I can only see 1 line of what the list box shows. I wanted it to show like it is in a wrap text view like all the text that would show on the listbox are compressed.

and also can the data show until i hit the search button? because now it shows the text on the listbox immediately after I select the data on the combobox1 and combobox2.

I can see that I can't add attachments here. How can I send you the file?

Thank you so much!
 
Upvote 0
You can upload your file to a share site such as OneDrive, DropBox, GoogleDrive, mark for sharing & post the link to the thread.
 
Upvote 0
I will upload the link to the file once I can use my personal laptop. There are strict security in my work so I'm not allowed to access file hosting sites.

Thank you so much
 
Upvote 0
I can see the file thanks, but can you please explain to me, why I should continue helping you, considering the fact that you have now posted this question to another site as well?


Cross posted https://www.excelforum.com/excel-pr...-excel-search-and-find-macro.html#post5094826

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,215,161
Messages
6,123,375
Members
449,098
Latest member
Jabe

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top