Today in this blog post I will show you how to create this search suggestion in a drop down list in Excel.
I have a list of Top 20 countries by GDP. I want to create a search suggestion mechanism in a drop-down, which would display the matching options as I type in the search bar. Something as shown below:
To follow along, download the file from here
Here is how you can do this:
- Insert a Combo Box (ActiveX Control) from the developer tab [Read on how to get the Developer Tab]
- Right click on the Combo Box and select Properties
- In the properties dialogue box, make the following changes
- AutoWordSelect: False
- LinkedCell: B3
- ListFillRange: DropDownList
- MatchEntry: 2 – fmMatchEntryNone
(Note that cell B3 is linked to the Combo Box, which means that anything you type in the Combo Box is entered in B3)
- Go to Developer tab and click on Design Mode. This will enable you to enter text in the Combo Box
- Put the following formula in cell F3 and drag it for the entire column (F3:F22)
=--ISNUMBER(IFERROR(SEARCH($B$3,E3,1),""))
This formula returns 1 when the text in the Combo Box is there in the name of the country on the left. For example, if you type UNI, then only the values for United States and United Kingdom are 1 and all the remaining values are 0
- Put the following formula in Cell G3 and drag it for the entire column (G3:G22)
=IF(F3=1,COUNTIF($F$3:F3,1),"")
This formula returns 1 for the first occurrence where Combo Box text matches the country name, 2 for the second occurrence, 3 for the third and so on. For example, if you type UNI, G3 cell will display 1 as it matches United States, and G9 will display 2 as it matches United Kingdom. Rest of the cells will be blank.
- Put the following formula in cell H3 and drag it for the entire column (H3:H22)
=IFERROR(INDEX($E$3:$E$22,MATCH(ROWS($G$3:G3),$G$3:$G$22,0)),"")
This formula stacks all the matching names together without any blank cells in between them.
- Now create a Named Range with the following formula
=$H$3:INDEX($H$3:$H$22,MAX($G$3:$G$22),1)
- And the final step. Right click on the Worksheet tab and select View Code. In the section on the right, paste the following code
ComboBox1.ListFillRange = "DropDownList"
ComboBox1.DropDown
End Sub
How to create a named range (for Step#6)
- Go to Fomulas –> Name Manager
- In the name manager dialogue box click New.
- It will open a New Name dialogue box. In the Name Field enter DropDownList
- In the Refers to Field enter the formula: =$H$3:INDEX($H$3:$H$22,MAX($G$3:$G$22),1)
Thats it!! You are all set with your own Google type Search bar for a drop down. For better look and feel, Cover the cell B3 with the Combo Box and hide all the columns with formula. You can now wow people with this amazing trick.
To follow along, download the file from here
--
{{{{ Rawalpindi-Islamabad Friends}}}}
************************************************************************************
All members are expected to follow these Simple Rules
Abuse of any kind (to the Group, or it's Members) shall not be tolerated
SPAM, Advertisement, and Adult messages are NOT allowed
This is not a Love, Dating Forum so sending PM or Chat Inv will be considered as illegal Act. will be BANED Instantly.
************************************************************************************
You received this message because you are subscribed to the Google
Groups "Pindi-Islamabad Friends" group.
To post to this group, send email to Pindi-Islamabad@googlegroups.com
To unsubscribe from this group, send email to
Pindi-Islamabad+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/Pindi-Islamabad?hl=en
---
You received this message because you are subscribed to the Google Groups "Pindi-Islamabad Friends" group.
To unsubscribe from this group and stop receiving emails from it, send an email to Pindi-Islamabad+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment