How to Create a Text Search Box

BB38

New Member
Joined
Jan 16, 2021
Messages
39
Office Version
  1. 365
Platform
  1. Windows
Hi -

In my spreadsheet, I'm trying to create a search box in cell E5 - that searches cells B10-B242 (the data in my table). The data is a set of unique names.

Ideally I want the user to type the name they are looking for in the search box, and then receive back in another box the cell number if the name exists in the database. If it doesn't I want it to say "not found". For names that it did find , i'd also like that name to be highlighted in its cell.

does that make sense? can anyone help?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Something like:
Excel Formula:
=IFERROR(MATCH(nametofind,rangetosearch,0),"not found")

In your case, nametofind is the value in E5, and rangetosearch is B10-B242.

If a match is found, the Match returns the index of the array you used to search (i.e. if a match is in the 4th cell of the array, Match will return 4). If there's no match, Match returns an error, hence the error handling.

To highlight the cell, you might be able to either
  1. Add a helper column with something like
    VBA Code:
    =MATCH($E$5,$B10,0)
    , and then a conditional formatting rule to highlight if not an error error (the cell is not a match)
    Excel Formula:
    NOT(ISERROR(cell))
  2. Or you could try a VBA solution to select and/or highlight the cell.
 
Upvote 0
Thank you. I am a relatively average excel user so...will try to figure these out. I appreciate it!
 
Upvote 0
Something like:
Excel Formula:
=IFERROR(MATCH(nametofind,rangetosearch,0),"not found")

In your case, nametofind is the value in E5, and rangetosearch is B10-B242.

If a match is found, the Match returns the index of the array you used to search (i.e. if a match is in the 4th cell of the array, Match will return 4). If there's no match, Match returns an error, hence the error handling.

To highlight the cell, you might be able to either
  1. Add a helper column with something like
    VBA Code:
    =MATCH($E$5,$B10,0)
    , and then a conditional formatting rule to highlight if not an error error (the cell is not a match)
    Excel Formula:
    NOT(ISERROR(cell))
  2. Or you could try a VBA solution to select and/or highlight the cell.
I am making progress here but it's not quite fully working:

1. How can I make the query not an "exact" match. Meaning if the name was say... "Walrus Rugs" but just typing "Wal" should show me the possible matches. I realize this is different from original query.
2. When the query returns me the row the name is in, it's giving me a number that is off by 10. How can I correct that?

This is for a new job and thank you for this help it is invaluable!
 
Upvote 0
  1. To get a fuzzy match, you can append a wildcard to the end, so it will return the first result that starts with the entered string. Your formula would turn into something like:
    Excel Formula:
    =MATCH($E$5 & "*",$B10,0)
    Showing all possible matches is slightly more complex where it would likely require you to filter the table in some way. Note you also can't use this to search for something within a name - only for results that start with your query. I see you're using O365 which is nice because it gives you some more options here. If you want anything more advanced, maybe look at FILTER or XLOOKUP.
  2. I don't know the format of your table and data but based on what you've mentioned, your range starts at the 10th row (B10), so that's the first place I'd look. I don't know if you modified any formulas, but if you're consistently off by 10, you can always just add 10 to the Match result to get the proper row.
 
Upvote 0
Solution
Something like:
Excel Formula:
=IFERROR(MATCH(nametofind,rangetosearch,0),"not found")

In your case, nametofind is the value in E5, and rangetosearch is B10-B242.

If a match is found, the Match returns the index of the array you used to search (i.e. if a match is in the 4th cell of the array, Match will return 4). If there's no match, Match returns an error, hence the error handling.

To highlight the cell, you might be able to either
  1. Add a helper column with something like
    VBA Code:
    =MATCH($E$5,$B10,0)
    , and then a conditional formatting rule to highlight if not an error error (the cell is not a match)
    Excel Formula:
    NOT(ISERROR(cell))
  2. Or you could try a VBA solution to select and/or highlight the cell.
I got the original goal completed. Can you expand on the "helper" column. I create another column but what do I change about the data. Forgive me for being dense. I haven't done a helper column and was unsure why I needed one to then try the highlighting solution.

Thanks again for all this help.

Brad
 
Upvote 0
Something like:
Excel Formula:
=IFERROR(MATCH(nametofind,rangetosearch,0),"not found")

In your case, nametofind is the value in E5, and rangetosearch is B10-B242.

If a match is found, the Match returns the index of the array you used to search (i.e. if a match is in the 4th cell of the array, Match will return 4). If there's no match, Match returns an error, hence the error handling.

To highlight the cell, you might be able to either
  1. Add a helper column with something like
    VBA Code:
    =MATCH($E$5,$B10,0)
    , and then a conditional formatting rule to highlight if not an error error (the cell is not a match)
    Excel Formula:
    NOT(ISERROR(cell))
  2. Or you could try a VBA solution to select and/or highlight the cell.
one other question: if I already have a function for another item in VBA (module 1) - how do I create/add another function? do I add it into the same module? I guess I don't understand how to put the formula you gave me into VBA (helper column with formula)....
 
Upvote 0
I got the original goal completed. Can you expand on the "helper" column. I create another column but what do I change about the data. Forgive me for being dense. I haven't done a helper column and was unsure why I needed one to then try the highlighting solution.

Thanks again for all this help.

Brad
No problem. The purpose of helper columns is to simplify formulas, you could get away without it, but it makes formulas more complex. The helper column contains the formula =MATCH($E$5,$B10&"*",0). This will return a number for all matches and #N/A for all non matches. The column can be hidden if you so choose. Then, use conditional formatting to reference this column and highlight all cells that are no errors =IF(NOT(ISERROR(helpercolumn)),1,0). The conditional formatting is applied to B10-B242.

If you didn't want to use a helper column, your conditional formatting formula would be something like =IF(NOT(ISERROR(MATCH($E$5,$B10&"*",0))),1,0). Disadvantage is a more complex formula but advantage is you don't need a helper column for the formula.

one other question: if I already have a function for another item in VBA (module 1) - how do I create/add another function? do I add it into the same module? I guess I don't understand how to put the formula you gave me into VBA (helper column with formula)....
In general, yes you do. You can add as many things as you want to a module. Sorry if I was confusing above, but this solution uses entirely excel formulas + conditional formatting, so you don't need to add any VBA.

See the spreadsheet below with some sample data.

Book1
ABCDEF
1Rep[helper column]
2Jones#N/AnameToFindresult
3Kivell#N/Asor5
4Jardine#N/A
5Gill#N/A
6Sorvino1
7Jones#N/A
8Andrews#N/A
9Jardine#N/A
10Thompson#N/A
11Jones#N/A
12Morgan#N/A
13Howard#N/A
14Parent#N/A
15Jones#N/A
16Smith#N/A
Sheet1
Cell Formulas
RangeFormula
F3F3=IFERROR(MATCH($E$3&"*",B2:B16,0),"not found")
C2:C16C2=MATCH($E$3&"*",B2,0)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:B16Expression=IF(NOT(ISERROR(C2)),1,0)textNO
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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