Search vs Find

Today I want to examine the Search function and the differences between the functions Search and Find.
On first glance they appear to do the same job. Both allow you to find a string within a sub string. Okay now that one sentence has caused many people to just click off this blog. But for those few go getters who have stayed, let me demonstrate the differences with an example.

The syntax for the SEARCH function is:

SEARCH( substring, string, [start_position] )substring is the substring that you want to find.
string is the string to search within.

start_position is optional. It is the position in string where the search will start. The first position is 1.

Let’s look at the following sentence…

The blue chicken has the best food in france.

(Now that’s a new search result for Google to find!)

If I wanted to find the starting position of the word france (18 character in the sentence) I could use either =Search or =Find.


A
B
1
The blue chicken has the best food in france.
2

3
 Result
Formula
4
18
=SEARCH("France",A1,1)
5
#VALUE!
=FIND("France",A1,1)
6
 18
 =SEARCH("fra*",A1,1)
7
 #VALUE!
 =FIND("fra*",A1,1)

Ah Ha!!! You exclaim, you forgot to capitalize the word France in your sentence (the spelling police are everywhere). You are correct, and yet the =Search function found the word while the Find function returned an error.

This is because the FIND function is case sensitive, while the SEARCH function is not. FIND looks for the exact match whereas SEARCH will just look for any match (uppercase or lowercase or mixture). And in my formulas I capitalized the letter F in France.

The Second difference between FIND and SEARCH is the ability to use Wildcard characters. The SEARCH function allows wildcard characters, while the FIND function does not.

Notice the wildcard in my third example  =SEARCH("fre*",A1,1

You can use the ? and * wildcard characters; use ~? And ~* to find the ? and * characters.

So right about now you are asking yourself, why would I ever use the find function when search seems so much more useful? Well the answer is case sensitivity. If you  need case sensitivity, then you need to use the FIND function.

So which do you prefer, Find or Search?



Find the Smallest Value in an Array based on a specific Item

Earlier today a co worker presented me with an Excel problem that he could not figure out. He wanted to find the lowest value in a table. Here is a short sample of the table he was looking at.

A
B
 C
1
ID
Product
 Sale Amount
2
10001
Hammer
                  15.50
3
10002
Saw
                    7.00
4
10003
Square
                  11.25
5
10004
Bracket
                  13.00
6
10005
Hammer
                  11.00
7
10006
Saw
                  12.00
8
10007
Square
                  10.75
9
10008
Saw
                  15.00
10
10009
Hammer
                  12.00
11
10010
Saw
                  13.50
12
10011
Square
                    6.40
13
10012
Bracket
                  13.00


So I thought to myself, easy I can just do a =Min formula on column C    =MIN(C:C) and return 6.40
However then he said, he wanted the minimum value of Saws in the table. In the above example that would be 7, not 6.40.

HMMMMM. No problem, I can use the =small function.

SMALL(array,k)

Now small returns the k-th smallest value in a data set. For example, the fifth smallest number.
Since I want the smallest number k = 1. If I wanted the second smallest number I would use 2.

So I wrap the small function around an IF statement.

=SMALL(IF(B2:B13="Saw",C2:C13,""),1)

NOW TO MAKE THIS WORK, TURN THE FORMULA INTO AN ARRAY
While editing the formula, press CTRL+SHIFT+ENTER

The result is 7 since the lowest sale amount for the product SAW is 7.

If he wanted the largest I could replace =SMALL with =LARGE.

Now he could use a cell reference to pull his value. =SMALL(IF(B2:B13=H1,C2:C13,""),1)

In this instance the value in cell H1 would be looked up in the formula. Now I added the cell reference after my original solution and received errors for some of my values in the list. To correct this, I needed to recalculate my formula as an array (While editing the formula, press CTRL+SHIFT+ENTER) after setting the cell reference value.

I like this solution since it is simple. His work around was to bring the table into MS Access and then create two queries to get the answer.

He walked away happy with new knowledge and I once again sat back basking in the glow of being the Excel go to guy.

So how would you have solved this Excel question?