# ***WINNERS ANNOUNCEMENT*** June/July 2008 Challenge of the Month



## MrExcel

I've posted a new *challenge of the month* today. Like the last challenge, this one will have many different approaches. Post your entries here. While the ultimate "best" entry wins the LiveLessons DVD, several podcast DVD's are available to anyone who proposes a significant advancement towards a cool solution.

Entries are due by 15 July 2008.

Bill Jelen


***WINNERS LIST PUBLISHED HERE***

http://www.mrexcel.com/pc18.shtml


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Looks like I get to be first:

Entered in B2 copied down as far as required (matches against the last colour occurrence in the cell):

=INDEX($E$2:$E$10,MAX(ISNUMBER(SEARCH($D$2:$D$10,A2))*(ROW($D$2:$D$10)-ROW($D$2)+1)))

Confirmed with Ctrl+Shift+Enter


This one matches against the first colour occurrence in the cell):

=INDEX($E$2:$E$10,MATCH(TRUE,ISNUMBER(SEARCH($D$2:$D$10,$A2)),0))

Confirmed with Ctrl+Shift+Enter


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

In case of multiple occurrences of individual colours (could include submatches too eg *red* and *red*ditch) the following will select the name against the colour with the highest number of occurrences:

=INDEX($E$2:$E$10,SUMPRODUCT(MAX(((LEN($A2)-LEN(SUBSTITUTE($A2,$D$2:$D$10,"")))/LEN($D$2:$D$10)=MAX((LEN($A2)-LEN(SUBSTITUTE($A2,$D$2:$D$10,"")))/LEN($D$2:$D$10)))*(ROW($D$2:$D$10)-ROW($D$2)+1))))

Confirmed with Ctrl+Shift+Enter


----------



## Oorang

*Re: June/July 2008 Challenge of the Month*

Got caught by the edit thingy. The full post should have been:


I did the challenge before I looked at the thread so this may have some overlap on RS but it's a bit different so I posted it anyway. 

It will find the first occurrence of any color in the color range in the cell's value and vlookup on that value. Place in B2 and copy down. Returns #VALUE! on fail. 

=VLOOKUP(INDEX($E$2:$E$10,SUMPRODUCT(--NOT(ISERROR(SEARCH($E$2:$E$10,A2))),ROW(INDIRECT("1:" & ROWS($E$2:$E$10))))-1),$E$2:$F$10,2)


----------



## barry houdini

*Re: June/July 2008 Challenge of the Month*

Here's one possibility.....

=LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

That's great Barry!


----------



## gingerafro

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)



taken a few minutes to get my head round it, but that is quality.


----------



## schielrn

*Re: June/July 2008 Challenge of the Month*

Here's a VBA approach:



		Code:
__


Sub returnName()
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    For j = 2 To Cells(Rows.Count, 4).End(xlUp).Row
        If InStr(1,Cells(i, 1).Value, Cells(j, 4).Value) Then Cells(i, 2).Value = Cells(j, 5).Value
    Next j
Next i
End Sub


----------



## Jon von der Heyden

*Re: June/July 2008 Challenge of the Month*

Yes very slick indeed, although I must ask, why have you specifically used 2^15?  I understand the bignum concept, only most people seem to use 9.99999999999999E+307.  Was there particular purpose or did you just throw it in knowing that it would be large enough?

Regards
Jon


----------



## Jonmo1

*Re: June/July 2008 Challenge of the Month*

Well, since no one else did a VBA UDF solution...Maybe I'll be the first to do that..

formula in B2 filled down is

=Jonmo1(A2,D:E)



		Code:
__


Public Function Jonmo1(C As Range, L As Range)
Dim MyArray As Variant
Dim X As Long, Y
MyArray = Split(C, " ")
Jonmo1 = ""
For X = LBound(MyArray) To UBound(MyArray)
    Y = Application.Match(MyArray(X), L.Columns(1), 0)
    If Not IsError(Y) Then
        Jonmo1 = L(Y, 2)
        Exit For
    End If
Next X
End Function


----------



## gingerafro

*Re: June/July 2008 Challenge of the Month*

max cell characters = 32767, 2^15 = 32768


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Maximum length of a cell is 2^15-1 so 2^15 will always be greater than the maximum possible return from SEARCH()


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*

You'd need to invoke a formula of the type as in:

http://www.mrexcel.com/forum/showthread.php?t=321942

http://www.mrexcel.com/forum/showthread.php?t=323188


Applied to the problem/task at hand...



		Code:
__


=LOOKUP(9.99999999999999E+307,
    SEARCH(" "&$D$2:$D$10&" "," "&A2&" "),
    $E$2:$E$10)

 
On Excel 2003 and beyond, convert D2:E10 into a list (Data|List|CreateList).

On earlier version, we would need define dynamic named ranges, say, KEYS and SLOTS, and invoke:



		Code:
__


=LOOKUP(9.99999999999999E+307,
    SEARCH(" "&KEYS&" "," "&A2&" "),
    SLOTS)

 


MrExcel said:


> I've posted a new *challenge of the month* today. Like the last challenge, this one will have many different approaches. Post your entries here. While the ultimate "best" entry wins the LiveLessons DVD, several podcast DVD's are available to anyone who proposes a significant advancement towards a cool solution.
> 
> Entries are due by 15 July 2008.
> 
> Bill Jelen


----------



## schielrn

*Re: June/July 2008 Challenge of the Month*

Aladin,

I could only get your formula to work for the phrases that did not end with the color.  The only way I could get it to work in all cases if the phrase ends with the color was by removing the &" "

=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10," "&A2),$E$2:$E$10)


----------



## cornflakegirl

*Re: June/July 2008 Challenge of the Month*

schielrn - there is a string of ascii characters at the end of each cell - a bunch of 160s (not sure what this is) ending with a 32 (space). i think mr excel is messing with our minds!

removing the &" " will mean that "redditch" becomes a problem again...


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*



schielrn said:


> Aladin,
> 
> I could only get your formula to work for the phrases that did not end with the color. The only way I could get it to work in all cases if the phrase ends with the color was by removing the &" "
> 
> =LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10," "&A2),$E$2:$E$10)


 
Given Bill's data...

<TABLE style="WIDTH: 320pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=426 border=0 x:str><COLGROUP><COL style="WIDTH: 119pt; mso-width-source: userset; mso-width-alt: 5778" width=158><COL style="WIDTH: 48pt" span=3 width=64><COL style="WIDTH: 57pt; mso-width-source: userset; mso-width-alt: 2779" width=76><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 119pt; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" width=158 height=17>*Phrases*</TD><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 48pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width=64>*Assignments*</TD><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 48pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width=64></TD><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 48pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width=64>*Keyword*</TD><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 57pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width=76>*Assigned to*</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>the ocean is blue</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A2&" "),$E$2:$E$10)'>Joe</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">blue</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Joe</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>I like the freddy shirt</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" align=middle x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A3&" "),$E$2:$E$10)' x:err="#N/A">#N/A</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">red</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Bob</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>blue is my favorite color</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A4&" "),$E$2:$E$10)'>Joe</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">yellow</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Mary</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>the ocean is red</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A5&" "),$E$2:$E$10)'>Bob</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">pink</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Fred</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>I like his red shirt</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A6&" "),$E$2:$E$10)'>Bob</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">orange</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Ralph</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>red is my favorite color</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A7&" "),$E$2:$E$10)'>Bob</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">brown</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Lora</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>the ocean is yellow</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A8&" "),$E$2:$E$10)'>Mary</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">white</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Tracy</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>I like his yellow shirt</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A9&" "),$E$2:$E$10)'>Mary</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">lavendar</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Earl</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>yellow is my favorite color</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A10&" "),$E$2:$E$10)'>Mary</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">magenta</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Jenny</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>the ocean is pink</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A11&" "),$E$2:$E$10)'>Fred</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>I like his pink shirt</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A12&" "),$E$2:$E$10)'>Fred</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" align=middle x:fmla='=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A13&" "),$E$2:$E$10)' x:err="#N/A">#N/A</TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD><TD class=xl25 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent"> </TD></TR></TBODY></TABLE>

=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10&" "," "&A2&" "),$E$2:$E$10)

should simply work.


----------



## cornflakegirl

*Re: June/July 2008 Challenge of the Month*

Aladin - did you see my post - the downloaded file isn't quite what it looks like...

I think 



		Code:
__


=IF(ISNA(LOOKUP(2^15,SEARCH(" "&$D$2:$D$10&" "," "&A2&" "),$E$2:$E$10)),LOOKUP(2^15,SEARCH(" "&$D$2:$D$10&CHAR(160)," "&A2&" "),$E$2:$E$10),LOOKUP(2^15,SEARCH(" "&$D$2:$D$10&" "," "&A2&" "),$E$2:$E$10))

 
will work - but it's nasty!


----------



## schielrn

*Re: June/July 2008 Challenge of the Month*

Ok thanks for the explanation, I see that now.


----------



## Jonmo1

*Re: June/July 2008 Challenge of the Month*



> there is a string of ascii characters at the end of each cell - a bunch of 160s (not sure what this is) ending with a 32 (space). i think mr excel is messing with our minds!


 
Hmm, LOL.  I thought maybe it was an accident or problem with the download of the file...

In that case, here's an update to my UDF to account for that...



		Code:
__


Public Function Jonmo1(C As Range, L As Range)
Dim MyArray As Variant
Dim X As Long, Y
Dim MyString As String
MyArray = Split(C, " ")
Jonmo1 = ""
For X = LBound(MyArray) To UBound(MyArray)
    MyString = Replace(MyArray(X), Chr(160), "")
    Y = Application.Match(MyString, L.Columns(1), 0)
    If Not IsError(Y) Then
        Jonmo1 = L(Y, 2)
        Exit For
    End If
Next X
End Function


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*



cornflakegirl said:


> Aladin - did you see my post - the downloaded file isn't quite what it looks like...
> 
> I think
> 
> 
> 
> Code:
> __
> 
> 
> =IF(ISNA(LOOKUP(2^15,SEARCH(" "&$D$2:$D$10&" "," "&A2&" "),$E$2:$E$10)),LOOKUP(2^15,SEARCH(" "&$D$2:$D$10&CHAR(160)," "&A2&" "),$E$2:$E$10),LOOKUP(2^15,SEARCH(" "&$D$2:$D$10&" "," "&A2&" "),$E$2:$E$10))
> 
> 
> will work - but it's nasty!


 
Emma,

If it's the case that A2 has a bunch of CHAR(160), it is simpler to invoke:


		Code:
__


=LOOKUP(9.99999999999999E+307,
   SEARCH(" "&$D$2:$D$10&" "," "&SUBSTITUTE(A2,CHAR(160),"")&" "),
   $E$2:$E$10)


----------



## Oorang

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)


Slick


----------



## Oaktree

*Re: June/July 2008 Challenge of the Month*

Bill,

How should this be mapped?

I borrowed my friend Red's blue and white shirt.


----------



## Lewiy

*Re: June/July 2008 Challenge of the Month*

Here’s another UDF option:
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>



		Rich (BB code):
__







		Rich (BB code):
__







		Rich (BB code):
__


Function ColorString(icolors As Range, istring As Range)<o:p></o:p>
Dim r As Range<o:p></o:p>
For Each r In icolors<o:p></o:p>
    If InStr(istring, r) > 0 And r.Value <> "" Then<o:p></o:p>
        ColorString = r.Value<o:p></o:p>
    End If<o:p></o:p>
Next r<o:p></o:p>
End Function


<o> </o>
=colorstring($D$2:$D$13,A2)


----------



## cornflakegirl

*Re: June/July 2008 Challenge of the Month*

Lewiy - that returns the colour, rather than the person it's assigned to...
(Also can't handle redditch).


----------



## Jonmo1

*Re: June/July 2008 Challenge of the Month*

OK, here's a slight improvement on my UDF. Doing the Replace Chr(160) before the Loop (instead of once for each loop), so it only has to do it once...Slight performance improvement..
Plus removed a couple unneeded pieces of code..

Although I don't see anything (code or formula) being any cooler than Barry's Formula.  That was just Sick!!



		Code:
__


Public Function Jonmo1(C As Range, L As Range) As String
Dim MyArray As Variant
Dim X As Long, Y
MyArray = Split(Replace(C, Chr(160), ""))
For X = LBound(MyArray) To UBound(MyArray)
    Y = Application.Match(MyArray(X), L.Columns(1), 0)
    If Not IsError(Y) Then
        Jonmo1 = L(Y, 2)
        Exit For
    End If
Next X
End Function


----------



## Jonmo1

*Re: June/July 2008 Challenge of the Month*

And now, to go into OverKill Mode. I don't think anyone has accounted for a possibility of having more than one color in the sentence... "My red car's exhaust is blue."

This now has an optional argument for the Nth Color...
If Nth is Omitted, the First color found in the string is used..
If Nth is Larger than the Number of colors in the string, the Last one is used.
=Jonmo1(A2,D:E,Nth)


		Code:
__


Public Function Jonmo1(C As Range, L As Range, Optional Nth As Long = 1) As String
Dim MyArray As Variant
Dim Counter As Long, X As Long, Y
MyArray = Split(Replace(C, Chr(160), ""))
For X = LBound(MyArray) To UBound(MyArray)
    Y = Application.Match(MyArray(X), L.Columns(1), 0)
    If Not IsError(Y) Then
        Counter = Counter + 1
        Jonmo1 = L(Y, 2)
        If Counter = Nth Then
            Exit For
        End If
    End If
Next X
End Function


----------



## pepijn

*Re: June/July 2008 Challenge of the Month*

Here is an other matrix funtion 

=INDEX($E$2:$E$10,MATCH(1,IF(SEARCH($D$2:$D$10,A2)>0,1,0),0))

confirm with ctrl + shift + enter


----------



## Jonmo1

*Re: June/July 2008 Challenge of the Month*

OK, now I'm really going off the deep end. Somebody stop me...

I've seen comments about how the string may contain a word like redditch (is that actually a word?). I think it was generally assumed that that word would NOT want to be found... But I figured, why not make it an option...

Options Options, I love options...

Now you have 2 optional arguments...
1st for the Nth Color to find.
2nd for Exact Match or Fuzzy Match..

4th argument (Fuzzy) 
Omitted = False
False = Findes an EXACT match, i.e. will not find redditch
True = Finds a FUZZY match, i.e. it WILL find redditch

I also added code to use only the actual used range, so if you use an entire column ref, it will only utilize the Used Range..

=Jonmo1(A1,D:E,Nth,True/False)



		Code:
__


Public Function Jonmo1(C As Range, L As Range, Optional Nth As Long = 1, _
Optional Fuzzy As Boolean = False) As String
Dim MyArray As Variant
Dim Pos() As Variant
Dim Word() As Variant
Dim MyRange As Range
Dim r As Range
Dim counter As Long, X As Long, Y
Set MyRange = Range(L(1, 1), L(L.Rows.Count, 1).End(xlUp).Offset(0, L.Columns.Count - 1))
If Fuzzy = False Then
    MyArray = Split(Replace(C, Chr(160), ""))
    For X = LBound(MyArray) To UBound(MyArray)
        Y = Application.Match(MyArray(X), MyRange.Columns(1), 0)
        If Not IsError(Y) Then
            counter = counter + 1
            Jonmo1 = MyRange(Y, 2)
            If counter = Nth Then Exit For
        End If
    Next X
Else
    For Each r In Range(MyRange.Columns(1).Address)
        X = InStr(1, C, r)
        If X > 0 Then
            counter = counter + 1
            ReDim Preserve Pos(1 To counter)
            ReDim Preserve Word(1 To counter)
            Pos(counter) = X
            Word(counter) = r
        End If
    Next r
    If counter < 1 Then Exit Function
    If Nth > UBound(Pos) Then Nth = UBound(Pos)
    X = Application.Small(Pos, Nth)
    Jonmo1 = Application.VLookup(Word(Application.Match(X, Pos, 0)), MyRange, 2, 0)
End If
End Function

 

OK, that should really be enough......LOL...


----------



## Patience

*Re: June/July 2008 Challenge of the Month*



jonmo1 said:


> redditch (is that actually a word?).



Finally I can contribute! Yes, Redditch is a place in England.


----------



## Jonmo1

*Re: June/July 2008 Challenge of the Month*



> Finally I can contribute! Yes, Redditch is a place in England.


 
Thank you, I thought I was going nutz...


----------



## Jonmo1

*Re: June/July 2008 Challenge of the Month*

OK, last one I promise...

After further consideration, I changed a rule in the UDF.
With the Nth option, it was set to use the Last Match if Nth was larger then the # of Matches Found.  In other words, in this sentence..
The blue ocean has a red boat in it.

If you put 3 or higher as the Nth, it would have used red.  Even though red was only the 2nd color in the sentence.

I now think that would probably be a bad idea, it could be misleading to think there is a 3rd color in the sentence when there actually isn't....so I changed it to return blank in that case instead...



		Code:
__


Public Function Jonmo1(C As Range, L As Range, Optional Nth As Long = 1, _
Optional Fuzzy As Boolean = False) As String
Dim MyArray As Variant
Dim Pos() As Variant
Dim Word() As Variant
Dim MyRange As Range
Dim r As Range
Dim counter As Long, X As Long, Y
Set MyRange = Range(L(1, 1), L(L.Rows.Count, 1).End(xlUp).Offset(0, L.Columns.Count - 1))
If Fuzzy = False Then
    MyArray = Split(Replace(C, Chr(160), ""))
    For X = LBound(MyArray) To UBound(MyArray)
        Y = Application.Match(MyArray(X), MyRange.Columns(1), 0)
        If Not IsError(Y) Then
            counter = counter + 1
            If counter = Nth Then
                Jonmo1 = MyRange(Y, 2)
                Exit For
            End If
        End If
    Next X
Else
    For Each r In Range(MyRange.Columns(1).Address)
        X = InStr(1, C, r)
        If X > 0 Then
            counter = counter + 1
            ReDim Preserve Pos(1 To counter)
            ReDim Preserve Word(1 To counter)
            Pos(counter) = X
            Word(counter) = r
        End If
    Next r
    If counter < 1 Then Exit Function
    If Nth > UBound(Pos) Then Exit Function
    X = Application.Small(Pos, Nth)
    Jonmo1 = Application.VLookup(Word(Application.Match(X, Pos, 0)), MyRange, 2, 0)
End If
End Function


----------



## arkusM

*Re: June/July 2008 Challenge of the Month*

Aladin,
 I am running XL2003 and have no issue with the first posted formula. It works perfectly.

M




Aladin Akyurek said:


> You'd need to invoke a formula of the type as in:
> 
> http://www.mrexcel.com/forum/showthread.php?t=321942
> 
> http://www.mrexcel.com/forum/showthread.php?t=323188
> 
> 
> Applied to the problem/task at hand...
> 
> 
> 
> Code:
> __
> 
> 
> =LOOKUP(9.99999999999999E+307,
> SEARCH(" "&$D$2:$D$10&" "," "&A2&" "),
> $E$2:$E$10)
> 
> 
> On Excel 2003 and beyond, convert D2:E10 into a list (Data|List|CreateList).
> 
> On earlier version, we would need define dynamic named ranges, say, KEYS and SLOTS, and invoke:
> 
> 
> 
> Code:
> __
> 
> 
> =LOOKUP(9.99999999999999E+307,
> SEARCH(" "&KEYS&" "," "&A2&" "),
> SLOTS)


----------



## arkusM

*Re: June/July 2008 Challenge of the Month*

Barry,

I get the max number of Characters in a Cell thing, but is your formula really counting the *len()* of the cell? Maybe I am missing something but it would appear it is simply looking for the value of 2^15. (I have yet to try this in an application of my own where my numbers are way greater than 32k). I am not trying to nit-pick but, there are some great solutions here that I like to understand so I can implement them in my work.

Thanks for your time.



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Search returns the position of the sought for term within the being searched string (so max value would be 32,767).  2^15 is simply one bigger than the absolute maximum value in the lookup range (ie SEARCH(D$2:D$10,A2)).  LOOKUP expects a sorted lookup range (sorted ascending) and if it doesn't find a match, it will return the next item in the lookup range which is less than the looked for value.  Thus 2^15 which match against whichever of the cells in D2:D10 returns a value when Search is applied (ie whichever color is present in the string).  The relative position D2:D10 is then used to return the person from column E.


Does that rambling explanation help or hinder?


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*



RichardSchollar said:


> Search returns the position of the sought for term within the being searched string (so max value would be 32,767). 2^15 is simply one bigger than the absolute maximum value in the lookup range (ie SEARCH(D$2:D$10,A2)). LOOKUP expects a sorted lookup range (sorted ascending) and if it doesn't find a match, it will return the next item in the lookup range which is less than the looked for value. Thus 2^15 which match against whichever of the cells in D2:D10 returns a value when Search is applied (ie whichever color is present in the string). The relative position D2:D10 is then used to return the person from column E.
> 
> 
> Does that rambling explanation help or hinder?


 
2^15 is I think an unfortunate variant on Excel's well-known constant:

9.99999999999999E+307

If you want to know how such a number as lookup value operates, see:

http://www.mrexcel.com/forum/showthread.php?t=102091

http://www.mrexcel.com/forum/showthread.php?t=310278


----------



## zapicm

*Re: June/July 2008 Challenge of the Month*

Hi all,

First post in this forum, got attracted by the challenge on the home page and I am happy to see the high level of the responses (I specially like the simplicity of the LOOKUP one).

Before searching the thread, I came up with a slightly variation of the arrays formulas proposed, but as it was not going to add anything new, I tried to come with an UDF that could use one of my favorite programming tools: regular expressions.  This is my attempt:


		Code:
__


Function MatchColors(strValue As String, rngList As Range) As String
    Dim regEx, Matches, i, strResult, bFlag
    
    'Create and set the parameters for the regular expressions object
    Set regEx = CreateObject("vbscript.regexp")
    regEx.Global = True
    regEx.IgnoreCase = True
    
    For i = 1 To rngList.Rows.Count
        'Just in case someone uses full column ranges
        If rngList.Cells(i, 1).Value = "" Then Exit For
        'Wrap the values on \b to mark word boundaries
        regEx.Pattern = "\b" & rngList.Cells(i, 1).Value & "\b"
        Set Matches = regEx.Execute(strValue)
        'If there is a match, add the relevant name to the string
        If Matches.Count > 0 Then
            'If that is not the first match, include a word separator
            If bFlag Then strResult = strResult & ", "
            strResult = strResult & rngList.Cells(i, 2).Value
            bFlag = 1
        End If
    Next
    MatchColors = strResult
End Function

The usage would be:
=MatchColors(A2,$D$2:$E$10)
And it should return a list of the names for all the colors present as complete words, separated by commas.


----------



## tjmcgough

*Re: June/July 2008 Challenge of the Month*

Hi everyone,

Was happy to see my question posted as the challenge. I'm a new user to this forum and appreciate all the responses.

Richard, have tried your solution and it solves most of the issue. However, i noticed a few limitations still exist;

1. If no keyword match is found the first result is still returned. Anyway to have a blank returned if no match found? 
2. If a new row is added to the keyword table, the entire formula "breaks". Was thinking of adding placeholder keywords that would never match to allow for future growth of new rows. Example, adding a bunch of rows with ">>>Unused For Now<<<", and then changing to the "real" keyword if/when needed.

Any ideas on how to fix one or both?

Many thanks,

Tom


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Hi Tom

i think the answer to both is to use Barry's formula (possibly with Aladin's modification).


----------



## rgdwar1

*Re: June/July 2008 Challenge of the Month*

=index($e$2:$e$10,match(1,search("*"&$d$2:$d$10&"*",a2),0))

Ctrl-shift-enter


----------



## rgdwar1

*Re: June/July 2008 Challenge of the Month*

Also, I realized that if no phrase was entered or one was accidentally deleted, I didn't have any code to catch this so I added the following:

=IF(A2="","No Phrase Entered",INDEX($E$2:$E$10,MATCH(1,SEARCH("*"&$D$2:$D$10&"*",A2),0)))

confirmed with CTRL-SHIFT-ENTER


----------



## arkusM

*Re: June/July 2008 Challenge of the Month*

Thanks Barry and Aladin.
I use the Lookup() and the 9.99999e+307 variable often.
But the 2^15 was intriguing, and I forgot/was-unaware of the exact function of the Search() formula. Barry your reason for using it makes sense. 

Thanks for the clarification and explanation.



Aladin Akyurek said:


> 2^15 is I think an unfortunate variant on Excel's well-known constant:
> 
> 9.99999999999999E+307
> 
> If you want to know how such a number as lookup value operates, see:
> 
> http://www.mrexcel.com/forum/showthread.php?t=102091
> 
> http://www.mrexcel.com/forum/showthread.php?t=310278


----------



## mgirvin

*Re: June/July 2008 Challenge of the Month*

Wow!

barry houdini's solution is quite clever! I am still trying to get my head fully around it...

Had you run into this problem before, or similar problem, or did you just think this up today?


----------



## wsjackman

*Re: June/July 2008 Challenge of the Month*

a (to me) more traditional equation would be
=INDIRECT("E"&SUMPRODUCT(NOT(ISERR(FIND($D$2:$D$10,A2)))*ROW($D$2:$D$10)))

an alternate would be to name the "color" range and when new colors were added, just change the named range

=INDIRECT("E"&SUMPRODUCT(NOT(ISERR(FIND(color,A2)))*ROW(color)))

with color defined as d2:d10


----------



## arkusM

*Re: June/July 2008 Challenge of the Month*



mgirvin said:


> Wow!
> 
> barry houdini's solution is quite clever! I am still trying to get my head fully around it...
> 
> Had you run into this problem before, or similar problem, or did you just think this up today?



I have run into this "problem" before, though my solution was ridiculously complex, cumbersome and "expensive". I wish that I had found this site long ago!! would have saved me time waiting for XL to calc!! Thanks to all who contribute to this board. God bless you.

M


----------



## wsjackman

*Re: June/July 2008 Challenge of the Month*

Barry Houdini's solution is great.  I will use it today, but will be working on a simple method to find any second or third "color" reference in the same line. [hidden columns and substitute and a reapplication of Barry's equation are highly probable] (People I work with know I always have plenty of complicated methods for doing things.)


----------



## zapicm

*Re: June/July 2008 Challenge of the Month*



wsjackman said:


> Barry Houdini's solution is great.  I will use it today, but will be working on a simple method to find any second or third "color" reference in the same line. [hidden columns and substitute and a reapplication of Barry's equation are highly probable] (People I work with know I always have plenty of complicated methods for doing things.)


The UDF that I posted should cover any number of colors on one line, if you try it please let me know if it worked.

Thanks!


----------



## Oorang

*Re: June/July 2008 Challenge of the Month*

Does Bill accept UDFs were accepted for challenge solutions?


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Yes I believe any kind of solution may be proposed.


----------



## zapicm

*Re: June/July 2008 Challenge of the Month*

I read the challenge again, and it does say that user defined functions, or even macros, are allowed.  By the way, other part of the challenge says that it has to be adaptable to any number of entries, you can use the full columns (D:E) with my formula


----------



## wsjackman

*Re: June/July 2008 Challenge of the Month*

I like the udf.
My application actually works better with the names in different columns
=substitute(A2,LOOKUP(2^15,SEARCH(D$2:D$10,A2),d$2:d$10)<!-- / message -->),"")
in column C 
for simplicty, i went to an empty column and reused the houdini formula referencing c2

The actual formula I used had vastly different ranges so I hope I have not done any of my typical typos in this formula
I could have continued for third matches but didnt need to for the data set i used


----------



## Oorang

*Re: June/July 2008 Challenge of the Month*

Has anyone break tested these over large datasets to see how they perform? (Obviously I haven't)


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

My idea was this for B2 and down (CSE, of course):

=OFFSET(D$1,SUM((IFERROR(FIND(D$1:D$10,A2),0)>0)*ROW(D$1:D$10))-1,1)

While that may not get me the win again this year since Harry Houdini's is a slicker approach, his can be improved upon.  This is shorter by a few characters and works well:

=LOOKUP(2^9,FIND(D$2:D$10,A2),E$2:E$10)

Great job Harry.


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

I meant this for Harry's formula:

=LOOKUP(9^6,FIND(D$2:D$10,A2),E$2:E$10)

which will work for all of the rows in 2007, and earlier versions.  From a character count perspective, I do not think it's possible to improve this and still maintain the ability to copy the formula down.


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

By the way, 9^5 is sufficient (in Harry's approach) since the limit to the number of characters in a cell is now 32,000 in Excel 2007.  The limit was just 1,000 characters in prior versions.  These alarmingly large numbers are overkill:  the "color" could at most be 32,000 characters into the string in a cell, so 9^4 is too small to account for the "ultimate" case, while 9^5 is overkill but will work in any situation, without exception.


----------



## Krishnakumar

*Re: June/July 2008 Challenge of the Month*



Aladin Akyurek said:


> Emma,
> 
> If it's the case that A2 has a bunch of CHAR(160), it is simpler to invoke:
> 
> 
> Code:
> __
> 
> 
> =LOOKUP(9.99999999999999E+307,
> SEARCH(" "&$D$2:$D$10&" "," "&SUBSTITUTE(A2,CHAR(160),"")&" "),
> $E$2:$E$10)



May be..

=LOOKUP(9.99999999999999E+307,SEARCH(" "&$D$2:$D$10," "&A2&" "),$E$2:$E$10)


----------



## wsjackman

*Re: June/July 2008 Challenge of the Month*



Daniel Ferry said:


> I meant this for Harry's formula:
> 
> =LOOKUP(9^6,FIND(D$2:D$10,A2),E$2:E$10)
> 
> which will work for all of the rows in 2007, and earlier versions. From a character count perspective, I do not think it's possible to improve this and still maintain the ability to copy the formula down.


 
Using named ranges [c =$D$2:$D$10 and n =$E$2:$E$10 x =9^6]
charactercount is reduced by

=LOOKUP(x,FIND(c,A2),n)


----------



## wsjackman

*Re: June/July 2008 Challenge of the Month*

typical typos for me
c needs to be cc, n needs to be nn, x needs to be xx


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*



wsjackman said:


> Using named ranges [c =$D$2:$D$10 and n =$E$2:$E$10 x =9^6]
> charactercount is reduced by
> 
> =LOOKUP(x,FIND(c,A2),n)


 

  

Obviously my post meant that my improvement on Houdini's formula was the shortest character count possible WITHOUT resorting to named formulas. One could simpy name any of the formulas that work, "zz".

Now all you need to enter is: 

=zz

But that's pointless. 

My improvement still reigns as the SHORTEST character count possible WITHOUT named formulas.

HOWEVER, dynamic ranges would be an improvement usability-wise, for the lookup tables...


----------



## Quasi

*Re: June/July 2008 Challenge of the Month*

Hi,

I`m a new person here . My first solution looks like that

_=INDEX($E$1:$E$10;MAX((IF(COUNTIF(A2;CONCATENATE("*";$D$2:$D$10;"*"));ROW($D$2:$D$10);""))))


_This is array formula (_Ctrl+Shift+Enter_)


Best regards,

Quasi


----------



## jindon

*Re: June/July 2008 Challenge of the Month*

How about ?
UDF
=VLookLike(A2, $E$2:$E$10)


		Code:
__


Function VLookLike(txt As Variant, rng As Range) As Variant
Dim myPtn As String
myPtn = "(" & Join(WorksheetFunction.Transpose(rng.Columns(1).Value),"|") & ")"
With CreateObject("VBScript.RegExp")
    .Pattern = myPtn
    If .test(txt.Value) Then myMatch = .execute(txt.Value)(0)
End With
VLookLike = rng.Columns(2).Cells(WorksheetFunction.Match(myMatch,rng.Columns(1),0)).Value
End Function


----------



## stanleydgromjr

*Re: June/July 2008 Challenge of the Month*

Here you go.

Before my macro:

Excel WorkbookABCDE1PhrasesAssigned toKeywordAssigned to2the ocean is blueblueJoe3I like this blue shirtredBob4blue is my favorite coloryellowMary5the ocean is redpinkFred6I like this red shirtorangeRalph7red is my favorite colorbrownLora8the ocean is yellowwhiteTracy9I like this yellow shirtlavendarEarl10yellow is my favorite colormagentaJeny11the ocean is pink12I like this pink shirt13redditch14the ocean is blue15I like this blue shirt16blue is my favorite color17the ocean is red18I like this red shirt19red is my favorite color20the ocean is yellow21I like this yellow shirt22yellow is my favorite color23the ocean is pink24I like this pink shirt25redditch26the ocean is blue27I like this blue shirt28blue is my favorite color29the ocean is red30I like this red shirt31red is my favorite color32the ocean is yellow33I like this yellow shirt34yellow is my favorite color35the ocean is pink36I like this pink shirt37redditchSheet1


After the macro:

Excel WorkbookABCDE1PhrasesAssigned toKeywordAssigned to2the ocean is blueJoeblueJoe3I like this blue shirtJoeredBob4blue is my favorite colorJoeyellowMary5the ocean is redBobpinkFred6I like this red shirtBoborangeRalph7red is my favorite colorBobbrownLora8the ocean is yellowMarywhiteTracy9I like this yellow shirtMarylavendarEarl10yellow is my favorite colorMarymagentaJeny11the ocean is pinkFred12I like this pink shirtFred13redditchBob14the ocean is blueJoe15I like this blue shirtJoe16blue is my favorite colorJoe17the ocean is redBob18I like this red shirtBob19red is my favorite colorBob20the ocean is yellowMary21I like this yellow shirtMary22yellow is my favorite colorMary23the ocean is pinkFred24I like this pink shirtFred25redditchBob26the ocean is blueJoe27I like this blue shirtJoe28blue is my favorite colorJoe29the ocean is redBob30I like this red shirtBob31red is my favorite colorBob32the ocean is yellowMary33I like this yellow shirtMary34yellow is my favorite colorMary35the ocean is pinkFred36I like this pink shirtFred37redditchBobSheet1




		Code:
__


Option Explicit
Sub ColorAssignedTo()
'
' ColorAssignedTo Macro
' Macro created 06/21/2008 by Stanley D. Grom, Jr.
'
    Dim LRA&
    Dim LRD&
    Application.ScreenUpdating = False
    LRA& = Cells(Rows.Count, 1).End(xlUp).Row
    LRD& = Cells(Rows.Count, 4).End(xlUp).Row
    With Range("B2")
        .FormulaArray = "=INDEX(R2C5:R" & LRD& & "C5,MATCH(1,SEARCH(""*""&R2C4:R" & LRD& & "C4&""*"",RC[-1]),0))"
        .Copy Range("B3:B" & LRA&)
    End With
    With Range("B2:B" & LRA&)
        .Copy
        .Value = .Value
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub



Have a great day,
Stan


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*



Daniel Ferry said:


> By the way, 9^5 is sufficient (in Harry's approach) since the limit to the number of characters in a cell is now 32,000 in Excel 2007.  The limit was just 1,000 characters in prior versions.  These alarmingly large numbers are overkill:  the "color" could at most be 32,000 characters into the string in a cell, so 9^4 is too small to account for the "ultimate" case, while 9^5 is overkill but will work in any situation, without exception.



The maximum length of a cell has been 32767 since at least xl2000 (it was 32000 in xl97 per xl97's specification limits).  2^15 carries meaning as it is exactly 1 more than the maximum length of a cell in xl2000 and above.


----------



## wsjackman

*Re: June/July 2008 Challenge of the Month*

9^5 is greater than 2^15 with fewer characters.


Is there any penalty, Time, processing, etc., for using a number greater than is needed?
similarly, is there any penalty, for using a number raised to a power vs using the written out number?
also, is there any penalty, for using a named constant rather than having the value in the formula

I have been bit by Excel's floating decimal method before.


----------



## mgirvin

*Re: June/July 2008 Challenge of the Month*

Wow, not only is Barry’s formula EXCELlent, but this formula from wsjackman is pretty cool too:

=INDIRECT("E"&SUMPRODUCT(NOT(ISERR(FIND($D$2:$D$10,A2)))*ROW($D$2:$D$10)))

One could even not hard code the E with this adaptation on wsjackman’s formula:

=INDIRECT(LEFT(ADDRESS(ROW($E$2),COLUMN($E$2),4),1)&SUMPRODUCT(NOT(ISERR(FIND($D$2:$D$10,A2)))*ROW($D$2:$D$10)))


----------



## mgirvin

*Re: June/July 2008 Challenge of the Month*

Quasi,

How did you get your formula to run with semi-colons? I only got it to work when I replaced the semi-colons with commas, such as this:

=INDEX($E$1:$E$10,MAX((IF(COUNTIF(A2,CONCATENATE("*",$D$2:$D$10,"*")),ROW($D$2:$D$10),""))))

Is there a trick that allows you to you separate arguments with semi-colons?


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

Richard:

I was referring to the number of characters that can be printed from a cell.  The new limit is 32k; the old is 1k.  This comes from the Excel Team Blog at MSDN:

http://blogs.msdn.com/excel/archive/2005/09/26/474258.aspx

At any rate, 9^5 works in all cases and is the most compact method possible.  It is also slightly faster than 2^15 (less multiplications going on).  But that takes us in a different direction.  I have been arguing for compactness of formula.  The QUICKEST formula would replace all of these large numbers generators with the constant: 

32767


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

For the record, I believe these formulas to be the best possible in their respective categories:

Shortest at 39 characters (without names):
=LOOKUP(9^6,FIND(D$2:D$10,A2),E$2:E$10)

Fastest:
=LOOKUP(32767,FIND(D$2:D$10,A2),E$2:E$10)

Most Convienent with Dynamic Ranges for the tables:
=LOOKUP(9^6,FIND(KEY,A2),ASSIGN)


----------



## stanleydgromjr

*Re: June/July 2008 Challenge of the Month*

Daniel Ferry,

With your rated "fastest" formula, a change to my original macro (which handles changing  ranges):



		Code:
__


Option Explicit
Sub ColorAssignedTo()
    Dim LRA&
    Dim LRD&
    Application.ScreenUpdating = False
    LRA& = Cells(Rows.Count, 1).End(xlUp).Row
    LRD& = Cells(Rows.Count, 4).End(xlUp).Row
    With Range("B2:B" & LRA&)
        .FormulaR1C1 = "=LOOKUP(32767,FIND(R2C[2]:R" & LRD& & "C[2],RC[-1]),R2C[3]:R" & LRD& & "C[3])"
        '.Copy
        '.Value = .Value
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub



Have a great day,
Stan


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

Stan:

I like your approach, as it compliments the "fastest" nature of the formula with this fast VBA approach (linear with no loops). 

You could optimize further by turning off calculation before setting the formula; and turning it back on afterwards.

For the scenario where you replace the formulas to values, you could improve it by not using the Windows Clipboard:

Change this:
With Range("B2:B" & LRA&)
.FormulaR1C1 = "=LOOKUP(32767,FIND(R2C[2]:R" & LRD& & "C[2],RC[-1]),R2C[3]:R" & LRD& & "C[3])"
.Copy
.Value = .Value
End With

To:
With Range("B2:B" & LRA&)
.FormulaR1C1 = "=LOOKUP(32767,FIND(R2C[2]:R" & LRD& & "C[2],RC[-1]),R2C[3]:R" & LRD& & "C[3])"
.Copy .Value
End With


Good job!

And you have a nice day as well.
Daniel


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

So, here is the list of best thus far including macros:


Formulas all based on Barry Houdini's approach:

Shortest at 39 characters (without names):
=LOOKUP(9^6,FIND(D$2:D$10,A2),E$2:E$10)

Quickest:
=LOOKUP(32767,FIND(D$2:D$10,A2),E$2:E$10)

Most Convienent with Dynamic Ranges for the tables:
=LOOKUP(9^6,FIND(KEY,A2),ASSIGN)<!-- / message -->


Quickest VBA based on stanleydgromjr's approach:

<CODE>
Option Explicit
Sub ColorAssignedTo()
Dim LRA&
Dim LRD&
with Application
.ScreenUpdating = False
.Calculation =xlCalculationManual 
LRA& = Cells(Rows.Count, 1).End(xlUp).Row
LRD& = Cells(Rows.Count, 4).End(xlUp).Row
With Range("B2:B" & LRA&)
.FormulaR1C1 = "=LOOKUP(32767,FIND(R2C[2]:R" & LRD& & "C[2],RC[-1]),R2C[3]:R" & LRD& & "C[3])"
'.Copy .Value
End With
.CutCopyMode = False
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
</CODE>


----------



## mgirvin

*Re: June/July 2008 Challenge of the Month*

Daniel Ferry,

Although I too think that Barry’s is still the best, I like your formula here also:

=OFFSET(D$1,SUM((IFERROR(FIND(D$1:D$10,A2),0)>0)*ROW(D$1:D$10))-1,1)

A slight variation is:

=OFFSET(E$1,SUM(ISNUMBER(SEARCH(D$2:D$10,A2))*ROW(D$2:D$10))-1,)


----------



## mgirvin

*Re: June/July 2008 Challenge of the Month*

So we got Barry’s straight to the point formula:

=LOOKUP(2^15,SEARCH(I$2:I$10,A2),J$2:J$10)

Wsjackman’s constructing a cell reference formula:

=INDIRECT("E"&SUMPRODUCT(NOT(ISERR(FIND($D$2:$D$10,A2)))*ROW($D$2:$D$10)))

And Daniel’s moving from a starting point formula:

=OFFSET(D$1,SUM((IFERROR(FIND(D$1:D$10,A2),0)>0)*ROW(D$1:D$10))-1,1)

Thank you all for helping me to see new concepts for solving the problem at hand.

For the formulas that have been entered so far, I have learned so much! Thanks to all the amazing Excel Masters here at the MrExcel Discussion Board.


----------



## wsjackman

*Re: June/July 2008 Challenge of the Month*

 A large problem with my original post

=INDIRECT("E"&SUMPRODUCT(NOT(ISERR(FIND($D$2:$D$10,A2)))*ROW($D$2:$D$10)))

is that if there are several matches, the wrong name or an error will occur.

The biggest problem with Barry Houdini's better equation is that only the first match is shown. 

(both meet the description of the challenge for one match, but can cause practical problems, especially with my formula)

If your security lets you use UDFs, they are probably the best way to go.


----------



## Quasi

*Re: June/July 2008 Challenge of the Month*



mgirvin said:


> Quasi,
> 
> How did you get your formula to run with semi-colons? I only got it to work when I replaced the semi-colons with commas, such as this:
> 
> =INDEX($E$1:$E$10,MAX((IF(COUNTIF(A2,CONCATENATE("*",$D$2:$D$10,"*")),ROW($D$2:$D$10),""))))
> 
> Is there a trick that allows you to you separate arguments with semi-colons?



Yes, You can change it in Windows - _Control Panel/Regional and Language Options. _

Here is a useful link
http://digilander.libero.it/foxes/Excel/Excel_How_to_change_the_argument_separator.htm


----------



## mgirvin

*Re: June/July 2008 Challenge of the Month*

wsjackman,

Thank you for pointing out the shortcomings of the formulas. I will look at some of the other solutions posted that address those issues. I still have received great benefit from the concepts presented so far!


----------



## mgirvin

*Re: June/July 2008 Challenge of the Month*

Quasi,

Cool! I had no idea. Thanks for the link.


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

Mike Mel Girvin:

I'm always preaching compactness of formula, so your slight variation on my original formula is interesting. The reason I went with mine instead of your slightly more compact formula is compactness of application, which takes it a step further than just the formula.

You see in a real application of this, it is likely that the lookup tables would grow. I can thus replace three of the range references with ONE dynamic range in this fashion:

=OFFSET(KEY,SUM((IFERROR(FIND(KEY,A2),0)>0)*ROW(KEY))-1,1)

Of course, yours has the advantage of working in all versions. I've been on a mission lately to force myself to use 2007's new formulas so they are as old hat to me as the original roster.

A variant taking the better points of yours and mine that would work in all versions is:

=OFFSET(E$1,SUM(ISNUMBER(FIND(KEY,A2))*ROW(KEY))-1)

Thanks for the compliment. I'm glad you liked the approach. I won the last contest Mr Excel posted (more than a year ago). I like my approach as well, but nothing can compare with Houdini's. I had never seen this problem before and had to dream-up the solution. This technique with the large number in the Lookup formula has apparently been drifting around this board for some time. Although people that use the largest number that Excel can fathom and call it some sort of CONSTANT, really get me. There is absolutely no reason to use a number larger than 32767 (the max number of character that fit in a cell). These guys are using a number billions of times bigger than that. I am convinced that this causes Excel's engine to work harder than needed. I like the 9^5 method as it is the most compact method that will get you to a number large enough to account for every possible character, AND it requires 10 fewer multiplication steps than 2^15. In processing terms, each multiplication step is expensive.

Thanks again!


----------



## wsjackman

*Re: June/July 2008 Challenge of the Month*

In processing, would 6E4 take more or less time than 9^5?


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

wsjackman:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o></o>
While I cannot speak with authority on the algorithm employed by Excel to interpret scientific notation, I can say that even if it were perfect you are still going to have four multiplication steps involved. First you are taking 10 and raising it to the 4th power, which means 10 * 10 * 10 * 10 = 10,000. That is 1E4 and it required three multiplication steps. Finally, you need to take that product and multiply by 4 to get 4E4, or 40,000. That is one more multiplication step giving a total of 4 multiplication steps.<o></o>
<o></o>
The 9^5 that I've been promoting also gets us there in 4 multiplication steps:<o></o>
<o></o>
9 * 9 * 9 * 9 * 9 = 59,049<o></o>
<o></o>
Both methods produce a number large enough in 4 multiplication steps and require only three characters of input, minimizing formula size. It is a good point that you bring up and I do not know which is more efficient in terms of processing. Since multiplication is so expensive, they are both in the same ballpark. It all depends on the relative algorithms employed by Excel to interpret both scientific notation and simple exponentiation. There may be a penalty by Excel’s calc engine on the scientific notation due to SN's slightly more complex interpretation, but I am speculating.


----------



## ghatfanazzam

*Re: June/July 2008 Challenge of the Month*



jonmo1 said:


> Well, since no one else did a VBA UDF solution...Maybe I'll be the first to do that..
> 
> formula in B2 filled down is
> 
> =Jonmo1(A2,D:E)
> 
> 
> 
> Code:
> __
> 
> 
> Public Function Jonmo1(C As Range, L As Range)
> Dim MyArray As Variant
> Dim X As Long, Y
> MyArray = Split(C, " ")
> Jonmo1 = ""
> For X = LBound(MyArray) To UBound(MyArray)
> Y = Application.Match(MyArray(X), L.Columns(1), 0)
> If Not IsError(Y) Then
> Jonmo1 = L(Y, 2)
> Exit For
> End If
> Next X
> End Function


I have a formula for this challenge , I don't know if any body else posted it before.
in cell B2 put this formula 
=VLOOKUP(INDEX($D$2:$D$10,MATCH(TRUE,COUNTIF(A2,"*"&$D$2:$D$10&"*")>0,0)),$D$2:$E$10,2,FALSE) then confirm it with Ctrl + Shift + Enter


----------



## ghatfanazzam

*Re: June/July 2008 Challenge of the Month*

I have a formula for this challenge , I don't know if any body else posted it before.
in cell B2 put this formula 
=VLOOKUP(INDEX($D$2:$D$10,MATCH(TRUE,COUNTIF(A2,"*"&$D$2:$D$10&"*")>0,0)),$D$2:$E$10,2,FALSE) then confirm it with Ctrl + Shift + Enter<!-- / message -->


----------



## mgirvin

*Re: June/July 2008 Challenge of the Month*

Daniel,

Instead of:
=OFFSET(E$1,SUM(ISNUMBER(FIND(KEY,A2))*ROW(KEY))-1)

why not:
=OFFSET(E$1,SUM(ISNUMBER(SEARCH(Key,A2))*ROW(Key))-1,)

SEARCH will find any case.

I like the dynamic range aspect!


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

Mike:

FIND is faster due to less overhead. If case desensitivity is important, then by all means use SEARCH...

Daniel


----------



## dedek

*Re: June/July 2008 Challenge of the Month*

This will also do the job...


IF(ISERROR(INDEX($E$2:$E$100;MATCH("ok";IF(SEARCH($D$2:$D$100;A2)>0;"ok";"");0)));"No keyword found";INDEX($E$2:$E$100;MATCH("ok";IF(SEARCH($D$2:$D$100;A2)>0;"ok";"");0)))

regards


----------



## gimmer

*Re: June/July 2008 Challenge of the Month*



MrExcel said:


> I've posted a new *challenge of the month* today. Like the last challenge, this one will have many different approaches.


 
Hi there, 
First Thanks for a great site, always a solution for my excel problems. 

I created at macro for this challange.

here is the macro:
Sub subtotal()
Dim text As String
Dim soeg As String
For Each c In Selection
text = c.Value
For i = 1 To 10
soeg = Cells(i, 4).Value
If InStr(1, text, soeg, vbTextCompare) Then
If soeg <> "" Then
c.Offset(0, 2).Value = soeg
End If
End If
Next i
Next c
End Sub

Thank you 
Lars (From Denmark)


----------



## D Kelly O'Day

*Re: June/July 2008 Challenge of the Month*

Here's my VBA approach that uses ranges for both phrases and keywords:



		Rich (BB code):
__


_Public Sub Keyword_Assign()
        Set Phrases = Worksheets("sheet1").Range("A1:A10000")
         No_keys = Range("d1").CurrentRegion.Rows.Count - 1
         ReDim Keys(No_keys, 2)
      For n = 1 To No_keys
            Keys(n, 1) = Cells(n + 1, 4)
            Keys(n, 2) = Cells(n + 1, 5)
      Next n
' Cycle through Keywords, get next keyword text string to be searched
    For i = 1 To No_keys
            Target = Cells(i + 1, 4)
            Assignee = Cells(i + 1, 5)
            'Search the phrase range for target using Find
                Set T_Cells = Phrases.Find(What:=Target, _
                    After:=Phrases.Cells(Phrases.Cells.Count), _
                    LookIn:=xlFormulas, LookAt:=xlPart, _
                    SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                    MatchCase:=False)
__           ' Check to see if anything found, if no, increment For/Next     _​_                If T_Cells Is Nothing Then GoTo 99
                Application.Goto reference:=T_Cells
            Do
              'Loop through T_Cells until last entry found
               Set T_found_cell = T_Cells
              Set T_Cells = Phrases.FindNext(After:=T_found_cell)
              rw = T_Cells.Row
             Cells(rw, 2) = Keys(i, 2)
             If T_found_cell.Row >= T_Cells.Row Then Exit Do
           Loop
         99
   Next i
End Sub_

D Kelly O'Day
http://processtrends.com


----------



## DiscoPistol

*Re: June/July 2008 Challenge of the Month*

This Code takes into account having more than 1 color.



		Code:
__


Private Sub CommandButton1_Click()
Dim rng As Range
Set rng = Range("A2:A25")


For Each Value In rng
x = 2
Do Until x = 10
Col = Cells(x, 4).Value
myint = InStr(1, Value, Col)
If myint > 0 Then
If Value.Offset(0, 1).Value <> 0 Then
Value.Offset(0, 1).Value = Value.Offset(0, 1).Value & ", " & Cells(x, 5).Value
Else
Value.Offset(0, 1).Value = Cells(x, 5).Value
End If
End If
x = x + 1

Loop
Next Value

End Sub


Not great but I feel a real sense of pride from doing that......

DP


----------



## jeffreyweir

*Re: June/July 2008 Challenge of the Month*

Here's a non-array and non-VBA solution. 

Cut the keyword/assigned table, and paste special transposed, so they go across the screen somewhere. I added another row at the top first, to make things match up nicely. So assuming the keyword/assigned table now runs horizontally from rows I1 to Q2, input this formula in every cell beneath: =IF(ISNUMBER(SEARCH(I$1,$A3)),$A3,"")

Copy this to other cells, all the way down to the last row that your dataset occupies. 

Then, in the Assigned To column, put this: =INDEX($I$1:$Q$2,2,MATCH(A3,I3:Q3,0))

No array formula necessary - although granted there is one cut and paste, and a bit of formula copying.


----------



## Andrew Fergus

*Re: June/July 2008 Challenge of the Month*

This challenge got me wondering if you could write a formula (not VBA) to return multiple values. The issue is the inability to loop using a formula without using a self- referencing formula. This exercise can be done with a single helper cell (which is the loop counter via a self referencing formula) and a circular reference formula like this :<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o></o>
1) select menu option Tools > Options > Calculation > tick 'Iteration' and set the 'Maximum Iterations' to a number greater than the number of lookup values (I used 100).<o></o>
2) for simplicity purposes name the lookup range 'LookUps' and the return values 'Returns' (in this case I2:I10 and J2:J10)<o></o>
3) In cell K1 enter the formula =K1+1 (this is the loop counter)<o></o>
4) This formula assumes the phrases to search are contained in column A, starting at A2.<o></o>
5) Enter the following formula into cell D2 and copy down: <o></o>


> =IF(AND($K$1=COUNTA(Lookups)+1, LEN(D2)>2),LEFT(D2,LEN(D2)-2), IF($K$1=1, "", D2) & IF($K$1>COUNTA(Lookups), "", IF(ISERROR(SEARCH(INDEX(Lookups,$K$1),$A2)), "", INDEX(Returns,$K$1) & ", ")))


<o></o>
<o></o>
To recalculate the values select cell K1, press the F2 key and press Enter.<o></o>
<o></o>
Andrew

P.S. this assumes the data is relatively 'clean' without the extra spaces etc. and doesn't take account of 'red' vs 'Redditch'.


----------



## cornflakegirl

*Re: June/July 2008 Challenge of the Month*

Andrew - I love that method! Just had a lot of fun playing with it.

This is a tweaked version - per Aladin's method earlier, that takes account of the CHAR(160)s and Redditch:



> =IF(AND($K$1=COUNTA(Lookups)+1, LEN(D2)>2),LEFT(D2,LEN(D2)-2), IF($K$1=1, "", D2) & IF($K$1>COUNTA(Lookups), "",IF(ISERROR(SEARCH(" "&INDEX(Lookups,$K$1)&" "," "&SUBSTITUTE($A2,CHAR(160),""))), "",INDEX(Returns,$K$1)&", ")))


----------



## Andrew Fergus

*Re: June/July 2008 Challenge of the Month*

Hi Emma

If you set the iteration to 1 (and keep pressing F9) you can watch how it progresses through the loop.

I also got to thinking about this yesterday - in particular my comment that you cannot loop using a formula. I (temporarily) forgot that you can by using a row() function in an array formula. I tried tweaking this to remove the helper cell, using a row() function and converting the formula to an array formula, but I got stuck and really should get on with my work.....

It's all good fun nonetheless.


Andrew

P.S.  the real challenge would be returning the phrases in the order they are found in the phrase being examined!


----------



## cornflakegirl

*Re: June/July 2008 Challenge of the Month*

Hehehe - I did exactly that - it was great!
I also thought of row() as soon as I saw your comment, but got stuck because you can't use CONCATENATE on an array, and I couldn't think of another way to do it. It was fun trying though!


----------



## drwhittle

*Re: June/July 2008 Challenge of the Month*

Here's another user-defined function. I tried to make it simulate a VLOOKUP function, except that the last argument gives the option for a case-sensitive lookup. It needs more error handling and it doesn't handle the case of multiple colors being in the same line (the first one found in the list wins), but then that wasn't a requirement. 



		Code:
__


Public Function DaveLookup(lookup_value, table_array As Range, col_index_num As Integer, Optional compare_option As Integer)
    Dim MyRow
    Dim iRow As Long
    Dim MyPos As Integer
    Dim Found As Boolean
 
    On Error GoTo Err
 
    Found = False
 
    With table_array
        iRow = 1
        For Each MyRow In table_array.Rows
 
            MyPos = InStr(1, lookup_value, .Cells(iRow, 1).Value, compare_option)
 
            If Not IsNull(MyPos) And MyPos > 0 Then
                DaveLookup = .Cells(iRow, col_index_num).Value
                Exit Function
            End If
            iRow = iRow + 1
        Next
    End With
Err:
    DaveLookup = "#N/A"
End Function


----------



## squiresk

*Re: June/July 2008 Challenge of the Month*

Greeting from Oz..

Certainly not the most sublime version, but I got it to work eventually. I learnt so much tackling this



		Code:
__


Sub Macro1()
Application.ScreenUpdating = False
Dim PhraseCount As Integer
Dim TableCount As Integer
Dim TableArray() As Variant
Dim i As Integer
Dim j As Integer
Dim PositionFound As Integer
TableCount = Range("D65536").End(xlUp).Row   'Find how many records in the lookup table
PhraseCount = Range("A65536").End(xlUp).Row  'Find how many records to be looked up
ReDim TableArray(TableCount, 2)         ' Resize the array
TableArray = Range("D2:E" & TableCount).Value   ' Shove the lookup table into an array
On Error Resume Next    ' Had to include this, because at the end, after all the ForNext'ing we get a
                        ' subscript out of range error.
                        ' I do not understand why
For j = 1 To TableCount    ' Loop through all the records to be searched
                           ' Then loop through each lookup value.
                           ' If it finds it, enter the corresponding lookup table value
    For i = 1 To PhraseCount
            PositionFound = InStr(Cells(i, 1), TableArray(j, 1))
        If PositionFound > 0 Then
        Cells(i, 2) = TableArray(j, 2)
        End If
    Next
Next
Application.ScreenUpdating = True
End Sub


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

Hello, Oz!

If you still want to learn a little more, consider these items:

You don't need to resize the array. Since you've dimmed TableArray as a variant, just go ahead with your next line where you set the variant to the range. Excel will automatically size the array for you as if you redimmed it like this:

ReDim TableArray(0 to TableCount - 1, 0 to 1)

There's a clue there to why you had to add the error checking. Although you did not specify (0 to TableCount) in your ReDim, unless you specifically instruct the VBA otherwise it will start at zero anyways. You have started your For Next loop at 1. Since the data will be in the array stating at element 0, you will run out of data just before the last loop cycle, raising the error. You are also skipping the first data at element 0.

To fix this just change your For Next loop for j to this:

For j = 0 to TableArray - 1

You should also change your 2nd dimension references downward by 1. So TableArray(j, 1) would become TableArray(j, 0)

and 

TableArray(j, 2) would become TableArray(j, 1)

This change is required for how Excel will automatically resize the array. You won't need the Error traping, but that is never a bad thing.

You don't need the PositionFound variable. You could replace the two lines that currently make use of it in the For i loop with:

If Instr(Cells(i, 1), TableArray(j, 0)) Then

But all and all, a very good effort. Try my changes and see what you think. Those will help you in almost every VBA program.

Regards,

Daniel


----------



## squiresk

*Re: June/July 2008 Challenge of the Month*

Thanks very much..

I'll will go through it again. I guess the main thing is the array 'elements' begin at zero, not 1. 

Kai, (in Austrialia)


----------



## Daniel Ferry

*Re: June/July 2008 Challenge of the Month*

Kai,

Unless you specifiy otherwise, yes, all array elements will begin at zero.

But let VBA resize the variant for you; no need to do the ReDim yourself unless you really needed the dimensions to begin at different numbers (which you don't).

When I optimize my code I alway look for lines and variables I can eliminate. That's why I spent a moment pointing some out. Less code is usually better.

I'll leave you with another thing to think about. Loops are great, but they can very quickly slow down your code, if there were hundreds or even thousands of elements in the lookup tables. In this exercise it is academic since there are only 10 elements in each.

But for learning purposes, it would be a good thing if you could figure-out a way to eliminate one of the loops or, better yet, both. This can be done, and would be a really great achievement. A clue is that Excel has many wonderful worksheet functions that can be called from VBA (i.e., WorksheetFunctions.Find). With some ingenuity, these can be used in a great many situations to remove loops from VBA code. To be sure, looping is still going on, but it is being done by very fast, compiled C++ code, and not poky interpreted VBA. In a real-world application this can dramatically increase your code execution speed, in some cases from minutes to run a given loop, improved to requiring just a fraction of a second with the method described.

Anyways, happy coding.

Regards,

Daniel


----------



## Jerry0

*Re: June/July 2008 Challenge of the Month*

Here's my VBA code entry.

Sub JuneChallenge()

LastRowColA = Range("A65536").End(xlUp).row
LastRowColD = Range("D65536").End(xlUp).row

For Each cel In Range("D2:D" & LastRowColD)
     keyword = cel: Assigned = cel.Offset(0, 1)

    With Worksheets(1).Range("a1:a" & LastRowColA)
        Set C = .Find(keyword, LookIn:=xlValues)
        If Not C Is Nothing Then
            firstAddress = C.Address
            Do
                C.Offset(0, 1).Value = Assigned
                Set C = .FindNext(C)
            Loop While Not C Is Nothing And C.Address <> firstAddress
        End If
    End With

Next cel

End Sub


----------



## Emanon

*Re: June/July 2008 Challenge of the Month*

This was my first solution. The method has been used by others though.

=INDEX(E$2:E$10,MATCH(FALSE,ISERR(SEARCH(D$2:D$10,A3)),0))


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Hi Daniel/Kai

That's not true that all array elements begin at zero - variant arrays created by assigning a range to a variant are always 2 dimensional 1-based arrays. 

Arrays created via using the Array function or by using Dim statements where you don't specify the lower bound (eg Dim myArray(10) As String) will use the module's Option Base statement (where the default value is 0 if you haven't specified it) to set the lower bound - hence if you use Option Base 1, then your arrays will be 1-based.

Certain functions (such as Split) return 0-based arrays no matter what the option base setting. Additionally, using the VBA prefix in front of the Array function (eg x = VBA.Array(1,2,3)) will always return a 0-based array no matter what the Option Base setting.

Because, dependent on how an array is created and what Option Base setting is active, arrays may or may not have a 0-base you will frequently see loop code written to account for this whereby the lower bound is determined by the LBound function:



		Code:
__


For i = LBound(myArray) To UBound(myArray) Step 1

 
in which case you never have to worry about how the array has been declared/created. This is especially useful when creating class modules as you may have no power over the class user to specify what base is used when they create an array that they might pass to the Class instance.


----------



## kmclean01

*Re: June/July 2008 Challenge of the Month*

Here is my (very long) VBA solution...sorry I am still pretty new to VBA (trying to teach myself):



		Code:
__


Sub finding()
    Dim rFound As Range
    counter = 1
    'Determine how many Phrases there are in the range
    textcountp = WorksheetFunction.CountA(Range("a:a")) - 1
    'Determine how many Keywords there are in the range
    textcountK = WorksheetFunction.CountA(Range("d:d")) - 1
    With Application.FindFormat.Font
        .Subscript = False
        .ColorIndex = xlAutomatic
    End With
    'Loops until you have gone through all of the keywords
    Do Until counter2 = textcountK
        'Loops until you have gone through all of the phrases
        Do Until counter = textcountp + 1
            On Error Resume Next
            Range("a2:a" & textcountp + 1).Select
            With Sheet1
                'Finds the keyword
                Set rFound = Range("a2:a" & textcountp + 1).Find(What:=Cells(2 + counter3, 4), After:=ActiveCell, LookIn:=xlFormulas, _
                    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                    MatchCase:=False, SearchFormat:=True).Activate
                If counter > 1 Then
                    'Finds the keyword again
                    Do Until again = counter
                       Selection.FindNext(After:=ActiveCell).Activate
                        If again = 0 Then
                            again = again + 2
                        Else
                        again = again + 1
                        End If
                    Loop
                End If
                counter = counter + 1
                ActiveCell.Offset(0, 1).Select
                'Copies the keyword if the cell is empty
                If ActiveCell.Value = Empty Then
                    Cells(2 + counter3, 5).Copy
                    ActiveSheet.Paste
                End If
                If again = 0 Then
                Else
                    again = 1
                End If
            On Error GoTo 0
                If Not rFound Is Nothing Then Application.Goto rFound, True
            End With
        Loop
        counter2 = counter2 + 1
        counter3 = counter3 + 1
        counter = 1
    Loop
End Sub

 
I will say, that I enjoyed trying to figure this out.


----------



## Gene Khalyapin

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)


 
Very impressive! I did not know this function can be used this way.

I just found this challenge and wanted to come up with my own solution for this problem (it's always exciting to work on a challenging problem).
This is the first solution I came up with: 
=INDEX($E$2:$E$10,SUM(IF(IF(ISERROR(FIND($D$2:$D$10,REPT(A2,ROWS($D$2:$D$10)))),0,1)=1,ROW($E$2:$E$10)-1,0)))

Array formula: Ctrl+Shift+Enter

I used REPT function (later I figured I could have used SUMPRODUCT + FIND to get the same results).


----------



## poreilly01

*Re: June/July 2008 Challenge of the Month*

This is my 1st post so I am not sure where things go.

There is so much code on the internet it seems futile to reinvent the wheel so I have used some VB script from Dave Hawley at Ozgrid
http://www.ozgrid.com/forum//showthread.php?t=61347&do=filter&fid=32201
and added one extra line to stop it running past the last non-balnk field (If rFound = "" Then Exit Sub) .

My solution goes -

run the macro "FindText" and it will provide a column (col B "Colour") containing the extracted colours contained in the adjacent text. Once you have a single word you can easily use vlookup.

Column A is named "FindRange" instead of "Phrases" & is the "FindRange" refered to in the macro & can be any length, no blanks in the list.

Column B named "Colour", is a list of colours returned by the macro to enable the vlookup to be performed.

Column C named "Assigned to" (original moved one column right) contains a vlookup to assign a name to each colour.

Column D is not used.

Column E & F have been reversed & are the original "Assigned to" & "Keyword" columns. "Keyword" is now a named range named "LookRange" to match the name in the macro for clarity & now has the column heading of "LookRange". It can be any length.

Columns C & G contain formulae & need to be dragged to the bottom of the corresponding list adjacent if extra rows are added.

When the macro runs all cells are populated with the answers.

Column G headed "No of Ea" is an extra I used to check the result. It totals the number of occurances of each keyword assigned to each name.

macro Code:

Sub FindText()
Dim rCell As Range, rFindIn As Range
Dim strWord As String, lLoop As Long
Dim rFound As Range

Set rFindIn = Range("FindRange")

For Each rCell In Range("LookRange")

strWord = rCell
Set rFound = rFindIn.Cells(1, 1)

For lLoop = 1 To WorksheetFunction.CountIf(rFindIn, "*" & strWord & "*")

Set rFound = rFindIn.Find(What:=strWord, After:=rFound, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)

rFound(1, 2) = strWord

If rFound = "" Then Exit Sub
Next lLoop

Next rCell 

End Sub


Column C Vlookup for the "assigned to" names -
=VLOOKUP(B2,$E$1:$F$11,2,FALSE)

Column G formula used to count the occurances for each name -
=IF(COUNTIF(B:B,LookRange)=0,"None",COUNTIF(B:B,LookRange))


----------



## poreilly01

*Re: June/July 2008 Challenge of the Month*

My vlookup

Column C Vlookup for the "assigned to" names -
=VLOOKUP(B2,$E$1:$F$11,2,FALSE)

should have been     =VLOOKUP(B2,E:F,2,FALSE)

this will extend to the end of the the columns so you can have as many entries as you like.


----------



## parmel

*Re: June/July 2008 Challenge of the Month*

Here's a macro that uses AutoFilter.  Sorry for the lack of indentation - I haven't posted to the board for a long time and I've forgotten how to mark a code block.

Sub assign_colors()
Dim rColors As Range
Dim c1 As Range
Dim c2 As Range
Dim rPhrases As Range
Dim sCriteria As String

Application.ScreenUpdating = False
Set rColors = Range(Cells(2, 4), Cells(2, 4).End(xlDown))
Set rPhrases = Range(Cells(1, 1), Cells(1, 1).End(xlDown))

For Each c1 In rColors 'loop through the colors
    sCriteria = "=*" & c1.Value & "*"
    rPhrases.AutoFilter Field:=1, Criteria1:=sCriteria
    For Each c2 In rPhrases 'assign the color to the phrase
        If c2.EntireRow.Hidden = False Then
            c2.Offset(0, 1).Value = c1.Offset(0, 1).Value
        End If
    Next c2
Next c1

'turn off autofilter
rPhrases.AutoFilter
Application.ScreenUpdating = True
End Sub


----------



## parmel

*Re: June/July 2008 Challenge of the Month*

Here's a macro that uses AutoFilter.  I'm sorry for the lack of indentation.  I've forgotten how to denote a code block.

Sub assign_colors()
Dim rColors As Range
Dim c1 As Range
Dim c2 As Range
Dim rPhrases As Range
Dim sCriteria As String

Application.ScreenUpdating = False
Set rColors = Range(Cells(2, 4), Cells(2, 4).End(xlDown))
Set rPhrases = Range(Cells(1, 1), Cells(1, 1).End(xlDown))

For Each c1 In rColors 'loop through the colors
    sCriteria = "=*" & c1.Value & "*"
    rPhrases.AutoFilter Field:=1, Criteria1:=sCriteria
    For Each c2 In rPhrases 'assign the color to the phrase
        If c2.EntireRow.Hidden = False Then
            c2.Offset(0, 1).Value = c1.Offset(0, 1).Value
        End If
    Next c2
Next c1

'turn off autofilter
rPhrases.AutoFilter
Application.ScreenUpdating = True
End Sub


----------



## gavinkelly

*Re: June/July 2008 Challenge of the Month*

Another UDF:


		Code:
__


Function ContainsText(Rng As Range, Text As String, Rng2 As Range) As String
'rng is first column of colours, text is the phrase, rng2 is second column of assigned values

n = 1
Dim myCell As Range
For Each myCell In Rng 'look in each cell

    If 0 < InStr(Text, myCell) Then
        ContainsText = Rng2(n)
        Exit For
    End If
n = n + 1
Next myCell

End Function


i will make it so that only one rng is required when i figure out how


----------



## gavinkelly

*Re: June/July 2008 Challenge of the Month*

Final version:


		Code:
__


Function ContainsText2(Rng As Range, Text As String) As String
'rng is table-i.e. in this example D2:E10, text is phrase

n = 1
For x = 1 To Rng.Count / 2    ' only works if 2 columns in rng
    If 0 < InStr(Text, Rng(n, 1)) Then
        ContainsText2 = Rng(n, 2)
        Exit For
    End If
n = n + 1
Next x

End Function


----------



## gavinkelly

*Re: June/July 2008 Challenge of the Month*

Ok i believe this is my improved code. 
i have included KeyWordCol & AssignedCol as optional arguments so anysize table can be used for the lookup and the order of the columns does not matter either.



		Code:
__


Function ContainsText(Rng As Range, Phrase As String, Optional KeyWordCol As Integer = 1, Optional AssignedCol As Integer = 2) As String

n = 1
For x = 1 To Rng.Rows.Count
    If 0 < InStr(Phrase, Rng(n, KeyWordCol)) Then
        ContainsText = Rng(n, AssignedCol)
        Exit For
    End If
n = n + 1
Next x

End Function


----------



## Noel Holland

*Re: June/July 2008 Challenge of the Month*

I added a column of sequential numbers in column C to act as a Key Reference number, then:

=VLOOKUP(SUMPRODUCT(NOT(ISERROR(SEARCH($D$2:$D$10,A2,1)))*($C$2:$C$10)),$C$2:$E$10,3,0)


Still getting my head round that solution from barry above. That is a seriously streamlined solution. Going to be interested in hearing how it works.


----------



## sulakvea

*Re: June/July 2008 Challenge of the Month*

--- the arguments of archie() are the cells in Column A

Function archie(TmpRng As Range) As String
 For i = 2 To Application.WorksheetFunction.CountA(Range("D:D"))
  If InStr(TmpRng.Text, Cells(i, 4)) > 0 Then archie = Cells(i, 5)
 Next i
 ' this last line is smth like the #N/A you would get w / vlookup
 If archie = "" Then archie = "archie is tired of looking"
End Function


----------



## enijhuis

*Re: June/July 2008 Challenge of the Month*

Why not a combination of a formula and VBA to make the solution easier to maintain:

Formula:
=VLOOKUP(ExtractColor(A2;$D$2:$D$10);D$2:$E$10;2;0)


VBA:

Private Function ExtractColor(sValue As String, rColors As Range) As Variant

    Dim sColor As String
    Dim rCell As Range

    'Look for the color in sValue based on the colors in range rColors
    For Each rCell In rColors
        If InStr(1, sValue, rCell.Text, vbTextCompare) > 0 Then
            'Color found
            sColor = rCell.Text
            Exit For
        End If
    Next

    'Return color or error
    ExtractColor = IIf(sColor = vbNullString, CVErr(xlErrNA), sColor)

End Function


----------



## WinteE

*Re: June/July 2008 Challenge of the Month*

And another UDF :



		Code:
__


Public Function AssignTo(Phrase As Range, KeywordsRange As Range) As String

Dim vKeyword As Variant
Dim vCheck As Variant

    For Each vKeyword In KeywordsRange
        vCheck = InStr(Phrase, vKeyword.Value)
        If vCheck > 0 Then
            AssignTo = vKeyword.Offset(0, 1).Value
            Exit Function
        End If
    Next vKeyword

End Function


----------



## robert phillips

*Re: June/July 2008 Challenge of the Month*

I didn't read the submission requirements and made a sort of 'whole house' solution before reading this thread. I sent it to mrexcel.com. My mistake. If you are interested in a vba only approach (from my humble thought process that is...), I can post the code although it is kind of formal and pretty darned long. Includes a couple buttons on sheet1. One button to process the lists, the other to reset (unprocess) the lists. I can email the spreadsheet too since we can't use attachments here.

Basically, I look for column headers, id the columns, complain about a missing column, get the extents of the list in each column, complain about an empty list, mark missing elements in a list with colored frames and '???', note more than one color in a phrase, try to catch colors with embedded parts of other color names eg, with bluegray, process the whole word  and not just the blue part.

All vba approach minimal use of built-in excel methods. (in my experience Vba itself was less prone to changes than the application specific extensions)

Robert Phillips
Westlake, Ohio


----------



## schielrn

*Re: June/July 2008 Challenge of the Month*

Robert,

See if this link helps with the HTML Maker:

http://www.mrexcel.com/forum/showthread.php?t=322557

Hope that helps.


----------



## RettaJ

*Re: June/July 2008 Challenge of the Month*

my, my barry - that is sweeet


----------



## Tennison

*Re: June/July 2008 Challenge of the Month*

Here is the VBA code,

For keywordIndex = 2 To .Cells(.Rows.Count, 4).End(xlUp).Row
strKeyword = .Cells(keywordIndex, .Range("Keyword").Column).Value
If VBA.Trim(strKeyword) <> "" Then
For PharseIndex = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
If VBA.InStr(1, .Cells(PharseIndex, 1).Value, strKeyword, vbTextCompare) > 0 Then
.Cells(PharseIndex, 2).Value = .Cells(keywordIndex, 4).Offset(0, 1).Value
End If
Next
End If
Next

Thanks 
Tennison


----------



## robert phillips

*Re: June/July 2008 Challenge of the Month*

A second try at posting a piece of the output from the processed lists....challengejune2008.rlp.xlsABCDE10yellow is my favorite color????MarymagentaJenny11I like his pink shirt??Fredgreen12pink is my favorite color??????FredJerry13the ocean is orange????RalphgrayMr. Ed14I like his orange shirtRalphbluegrayTomBob15the grass is greener???16orange is my favorite color????Ralph17the ocean is brown?????Lora18I like his brown shirt?Lora19brown is my favorite color?????Lora20the ocean is white?????Tracy21I like his white shirt?Tracy22white is my favorite color?????Tracy23hops are green???24the ocean is lavendar??Earl25I like his lavendar shirt??????Earl26magenta tie and pink shirtJenny ##27wear the bluegray hatTomBob28the sun is gold???29???30bring the gray shirtMr. EdSheet1


----------



## robert phillips

*Re: June/July 2008 Challenge of the Month*

I'm starting to get the hang of working with board. Here's the MODULE code.



		Rich (BB code):
__


'ASSUMPTIONS: LISTS ON ACTIVESHEET

Option Explicit
Option Compare Text

Const None = -4142
Const White = 2
Const BriteRed = 3
Const BriteGreen = 4
Const Blue = 5
Const BriteYel = 6
Const Magenta = 7
Const Cyan = 8
Const Darkred = 9
Const DarkGreen = 10
Const LtBlue = 34
Const LtGreen = 35
Const ToolTip = 36
Const Pink = 38
Const Violet = 39
Const Tan = 40
Const Teal = 42
Const LimaBean = 43
Const Pumpkin = 44
Const Orange = 45
Const Wine = 54

Type PhraseAssign
  Phrase As String  'the phrase
  Color As String   'the keyword
  Name As String    'the assignment
End Type

Type KeyAssign
  Color As String  'the keyword
  Name As String   'the assignee
End Type

Public ProcessRun As Boolean
Private OkToProcess As Boolean

Private LastPhrase As Long
Private LastPhraseAssign As Long
Private LastKeyWord As Long
Private LastKeyAssign As Long

Private ModuleName$
'PhraseCol 1, PhraseAssignCol 2, KeyWordCol 3, KeyAssignCol 4
Private FieldCols(1 To 4) As String

Private PhraseAssignments() As PhraseAssign
Private KeyAssignments() As KeyAssign
Private KeyOrder() As KeyAssign

'ASSUMPTIONS: LISTS ON ACTIVESHEET
Public Sub ProcessAllLists()
  On Error GoTo BeSafe
  
  Application.ScreenUpdating = False
  ModuleName$ = "ProcessAllLists"
  
  FindColumnHeaders
  If OkToProcess Then
    FindListExtents
    If OkToProcess Then
      ProcessKeywords
      If OkToProcess Then
        ProcessPhrases
      End If
    End If
  End If
  
  If Not OkToProcess Then
    MsgBox "Please make corrections."
  End If
  
  StepOut
  Application.ScreenUpdating = True
  Exit Sub
  
BeSafe:
  ErrorHandler

End Sub

'ASSUMPTIONS: LISTS ON ACTIVESHEET
Public Sub UnProcessLists()
  Dim i As Integer
  Dim Row1$, Row2$
  
  On Error GoTo BeSafe
  ModuleName$ = "UnProcessLists"
    
  Row1$ = "2"
  Row2$ = CStr(LastPhraseAssign)
  Range(FieldCols(2) & Row1$ & ":" & FieldCols(2) & Row2$).ClearFormats
  Range(FieldCols(2) & Row1$ & ":" & FieldCols(2) & Row2$).ClearContents
  Row2$ = CStr(LastKeyWord)
  Range(FieldCols(3) & Row1$ & ":" & FieldCols(3) & Row2$).ClearFormats
  Row2$ = CStr(LastKeyAssign)
  Range(FieldCols(4) & Row1$ & ":" & FieldCols(4) & Row2$).ClearFormats
  
  StepOut
  Exit Sub

BeSafe:
  ErrorHandler

End Sub

'ASSUMPTIONS: LISTS ON ACTIVESHEET
'ASSUMPTIONS: Headers on Row 1
Private Sub FindColumnHeaders()
  Dim GotField(1 To 4) As Boolean
  Dim i, j, LastCol As Integer
  Dim FieldNames(1 To 4), TmpCol As String
  
  On Error GoTo BeSafe
  ModuleName$ = "FindColumnHeaders"
  
  'Look for similar, give a little leeway to user
  FieldNames(1) = "Phrase"
  FieldNames(2) = "Assigned"
  FieldNames(3) = "Keyword"
  FieldNames(4) = "Assignee"
  'rely on vbcompiler to init booleans to false
  
  With ActiveSheet
    .Range("IV1").Select
    Selection.End(xlToLeft).Select
    LastCol = Selection.Column
    
    Select Case LastCol
      Case Is < 4
        MsgBox "You seem to be missing a necessary data column." & vbCrLf & "This worksheet should contain 4 columns with headers." & vbCrLf & "They should be 'Phrases', 'Assigned To', 'Keyword', and 'Assignee' (person name)."
        OkToProcess = False
        Exit Sub
      
      Case Else
        For i = 1 To LastCol
          TmpCol = NumToLtr(i)
          For j = 1 To 4
            If InStr(1, Range(TmpCol & "1").Value, FieldNames(j)) > 0 Then
              If GotField(j) = True Then  'uh oh, already had one by that name
                MsgBox "It appears there are two columns with similar field names. Please correct."
                OkToProcess = False
                Exit Sub
              Else
                FieldCols(j) = TmpCol
                GotField(j) = True
                Exit For
              End If
            End If
          Next
          'loop not worth it
          OkToProcess = GotField(1) And GotField(2) And GotField(3) And GotField(4)
          If OkToProcess Then Exit For  'take first 4 qualifiers by default
        Next
    End Select
  End With
  
  Exit Sub
  
BeSafe:
  ErrorHandler
    
End Sub

'ASSUMPTIONS: LISTS ON ACTIVESHEET
Private Sub FindListExtents()
  Dim i As Long
  Dim Row$
  
  On Error GoTo BeSafe
  ModuleName$ = "FindListExtents"
  
  With ActiveSheet
    '1 LastPhrase, 2 LastPhraseAssign, 3 LastKeyWord, 4 LastKeyAssign
    Range(FieldCols(1) & "65536").Select
    Selection.End(xlUp).Select
    LastPhrase = Selection.Row
    If LastPhrase < 2 Then
      MsgBox "There are no phrases to process."
      OkToProcess = False
      Exit Sub
    Else
      LastPhraseAssign = Selection.Row
    End If
    
    Range(FieldCols(3) & "65536").Select
    Selection.End(xlUp).Select
    LastKeyWord = Selection.Row
    If LastKeyWord < 2 Then
      MsgBox "There are no keywords to process."
      OkToProcess = False
      Exit Sub
    End If
    
    Range(FieldCols(4) & "65536").Select
    Selection.End(xlUp).Select
    LastKeyAssign = Selection.Row
    If LastKeyAssign < 2 Then
      MsgBox "There is no one assigned to the keywords."
      OkToProcess = False
      Exit Sub
    End If
    
  End With

  'normalize
  If LastKeyWord > LastKeyAssign Then
    LastKeyAssign = LastKeyWord
  Else
    LastKeyWord = LastKeyAssign
  End If
    
  ReDim PhraseAssignments(2 To LastPhrase)
  ReDim KeyAssignments(2 To LastKeyWord)
  
  With ActiveSheet
    For i = 2 To LastPhrase
      Row$ = CStr(i)
      'if someone left a blank inside the phrase list
      PhraseAssignments(i).Phrase = Trim$(.Range(FieldCols(1) & Row$).Value)
      If Len(PhraseAssignments(i).Phrase) = 0 Then
        PhraseAssignments(i).Phrase = "???"
      End If
    Next
    
    For i = 2 To LastKeyWord   'row 1 field names
      Row$ = CStr(i)
      KeyAssignments(i).Color = Trim$(.Range(FieldCols(3) & Row$).Value)
      KeyAssignments(i).Name = Trim$(.Range(FieldCols(4) & Row$).Value)
      .Range(FieldCols(3) & Row$).Select
      'if someone forgot to put a name with a color or left a blank in the list
      If Len(KeyAssignments(i).Color) = 0 Then
        KeyAssignments(i).Color = "???"
      End If
      .Range(FieldCols(4) & Row$).Select
      If Len(KeyAssignments(i).Name) = 0 Then
        KeyAssignments(i).Name = "???"
      End If
    Next
  End With

  'Clean Up Any Prior Processing, unmark cells, clear assigned to list
  UnProcessLists
  
  'POSTPROCESS to COLOR FRAMES
  With ActiveSheet
    For i = 2 To LastKeyWord
      Row$ = CStr(i)
      If KeyAssignments(i).Color = "???" Then
        .Range(FieldCols(3) & Row$).Select
        FrameCell Teal
      End If
      If KeyAssignments(i).Name = "???" Then
        .Range(FieldCols(4) & Row$).Select
        FrameCell Teal
      End If
    Next
  End With
  
  Exit Sub

BeSafe:
  ErrorHandler

End Sub

'ASSUMPTIONS: LISTS ON ACTIVESHEET
Private Sub ProcessKeywords()
  Dim OrderChanged As Boolean
  Dim i, j, k, Longest, TmpLen1, TmpLen2, TmpOrder1 As Integer
  Dim Order() As Integer
  
  'CREATE ORDERED LIST OF LONGEST COLOR NAME TO SHORTEST COLOR NAME
  'USED TO LOCATE CORRECT COLORNAME IN PHRASE WHEN TWO OR MORE COLOR NAMES
  'HAVE THE SAME SUB PARTS LIKE BLUE AND BLUEGRAY. CHECK FOR BLUEGRAY FIRST
  
  On Error GoTo BeSafe
  ModuleName$ = "ProcessKeywords"
  
  OkToProcess = True
  
  ReDim Order(2 To LastKeyWord, 2) As Integer
  
  For i = 2 To LastKeyWord          'current user order
    Order(i, 1) = Len(KeyAssignments(i).Color) 'colorname length
    Order(i, 2) = i                            'current order on list
  Next
  
  For i = 2 To UBound(Order)
    TmpLen1 = Order(i, 1)   'current length
    OrderChanged = False
    For j = i To UBound(Order)
      TmpLen2 = Order(j, 1) 'next length
      If TmpLen2 > TmpLen1 Then
        TmpLen1 = TmpLen2
        OrderChanged = True
        Longest = j         'list pointer
      End If
    Next
    If OrderChanged Then
      TmpLen1 = Order(Longest, 1)      'color length
      TmpOrder1 = Order(Longest, 2)    'list position pointer
      Order(Longest, 1) = Order(i, 1)  'move smaller up to longest
      Order(Longest, 2) = Order(i, 2)  'move listpointer with it
      Order(i, 1) = TmpLen1            'move longest to beginning
      Order(i, 2) = TmpOrder1          'move listpointer with it
    End If
  Next
  
  ReDim KeyOrder(2 To LastKeyWord)
  
  For i = 2 To LastKeyWord
    KeyOrder(i).Color = KeyAssignments(Order(i, 2)).Color
    KeyOrder(i).Name = KeyAssignments(Order(i, 2)).Name
  Next
  
  Exit Sub

BeSafe:
  ErrorHandler

End Sub

'ASSUMPTIONS: LISTS ON ACTIVESHEET
Private Sub ProcessPhrases()
  Dim GotColor As Boolean
  Dim KeyLen, KeyStart, PhraseLen As Integer
  Dim i, j, k As Long
  Dim Row$
  
  On Error GoTo BeSafe
  ModuleName$ = "ProcessPhrases"
  
  With ActiveSheet
    For i = 2 To LastPhrase
      Row$ = CStr(i)
      GotColor = False
      If PhraseAssignments(i).Phrase <> "???" Then
        For j = 2 To LastKeyWord
          KeyStart = InStr(1, PhraseAssignments(i).Phrase, KeyOrder(j).Color)
          If KeyStart > 0 Then
            GotColor = True
            PhraseAssignments(i).Name = KeyOrder(j).Name
            .Range(FieldCols(2) & Row$).Value = PhraseAssignments(i).Name
            If PhraseAssignments(i).Name = "???" Then
              .Range(FieldCols(2) & Row$).Select
              FrameCell DarkGreen
            End If
            For k = 2 To LastKeyWord
              'now check the other colors too...
              If k <> j Then
                If InStr(1, KeyOrder(j).Color, KeyOrder(k).Color) = 0 Then
                  '(k)Color isn't a subpart of a longer colorname (j)Color
                  'so go ahead and test for a second color
                  If InStr(1, PhraseAssignments(i).Phrase, KeyOrder(k).Color) > 0 Then
                    'uh oh, two+ colors
                    .Range(FieldCols(2) & Row$).Select
                    .Range(FieldCols(2) & Row$).Value = .Range(FieldCols(2) & Row$).Value & " ##"
                    FrameCell Orange
                    Exit For
                  End If
                End If
              End If
            Next
            Exit For
          End If
        Next
        'uh oh, no keyword color associated with phrase
        If Not GotColor Then
          .Range(FieldCols(2) & Row$).Select
          .Range(FieldCols(2) & Row$).Value = "???"
           FrameCell DarkGreen
        End If
      Else
        'a blank phrase in the list
        .Range(FieldCols(2) & Row$).Select
        .Range(FieldCols(2) & Row$).Value = "???"
        FrameCell DarkGreen
      End If
    Next
  End With
  
  Exit Sub
  
BeSafe:
  ErrorHandler

End Sub

'ASSUMPTIONS: LISTS ON ACTIVESHEET
Private Sub StepOut()
  Dim i As Integer
  
  For i = 1 To 256
    If Len(Trim(Cells(1, i).Value)) = 0 Then
      Cells(1, i).Select
      Exit For
    End If
  Next
End Sub

'ASSUMPTIONS: LISTS ON ACTIVESHEET
Private Sub FrameCell(HiliteColor)
  
  With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = HiliteColor
  End With
  
  With Selection.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = HiliteColor
  End With
  
  With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = HiliteColor
  End With
  
  With Selection.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = HiliteColor
  End With
    
End Sub

'ASSUMPTIONS: LISTS ON ACTIVESHEET
Private Sub UnFrameCell()
  With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlNone
  End With
  
  With Selection.Borders(xlEdgeTop)
    .LineStyle = xlNone
  End With
    
  With Selection.Borders(xlEdgeRight)
    .LineStyle = xlNone
  End With
    
  With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlNone
  End With
End Sub

Private Function NumToLtr(Num) As String
  Dim Letter1 As Integer, Letter2 As Integer
  
  Letter2 = (Num Mod 26)
  Letter1 = Int(Num / 26) + (Letter2 = 0)
  Letter2 = -(Letter2 = 0) * 26 + Letter2
  If Letter1 > 0 Then
    NumToLtr = Chr(Letter1 + 64)
  End If
  NumToLtr = NumToLtr & Chr(Letter2 + 64)

End Function

Private Sub ErrorHandler()
  
  MsgBox "Processing was interrupted in Module:" & ModuleName$ & vbCrLf & Err.Description
  Err.Clear
  OkToProcess = False
  Application.ScreenUpdating = True

End Sub




Here's SHEET1 code for 2 command buttons named: ProcessLists and Reset



		Rich (BB code):
__


Option Explicit
Option Compare Text

Private Sub ProcessLists_Click()
  ProcessAllLists
  ProcessRun = True
  Application.ScreenUpdating = True 'just in case
End Sub

Private Sub Reset_Click()
  If ProcessRun Then
    UnProcessLists
    ProcessRun = False
  Else
    'have to setup arrays first
    MsgBox "Please run Process Lists first...."
  End If
  Application.ScreenUpdating = True 'necessary
End Sub


----------



## indiaravi

*Re: June/July 2008 Challenge of the Month*

Hi Mr. Jelen
Please look at this Macro in response to your "Challenge of the Month Jun / Jul 2008"
Warm Regards


Sub Macro1()

' Macro recorded 7/4/2008 by INDIARAVI

Dim KWend As Long, i As Long, Phrase As String, KW As String, PhraseEnd As Long, j As Long, WSEnd As Long
WSEnd = Range("A1").End(xlDown).Row + 1
KWend = Range("D" & WSEnd).End(xlUp).Row
PhraseEnd = Range("A" & WSEnd).End(xlUp).Row
For i = 2 To KWend
KW = Range("D" & i).Value
For j = 2 To PhraseEnd
Phrase = Range("A" & j).Value
If InStr(Phrase, KW) > 0 Then
Range("B" & j).Value = Range("E" & i).Value
End If
Next j
Next i
End Sub


----------



## VIJAYKUMAR SHETYE

*Re: June/July 2008 Challenge of the Month*

This is the best I could manage

=OFFSET(E1,MATCH(1,IF(SEARCH(D2:D4,A2,1)>0,1,0)),0,1,1)

Vijaykumar Shetye,
India


----------



## Nenad Stojkovski

*Re: June/July 2008 Challenge of the Month*

Did not know about the posts and threads before creating this UDF so here is another variation.

I really like the simple solution though:
=LOOKUP(2^15,SEARCH(D$2:D$11,A2),E$2:E$11)) 

Wow!

'---------------------------------------------------------------------------------------
' Module    : UDF
' DateTime  : 7/8/2008 14:02
' Author    : Nenad Stojkovski
' Purpose   : MRExcel Challange June 2008
'---------------------------------------------------------------------------------------
Option Explicit
'---------------------------------------------------------------------------------------
' Procedure : us of  the UDF: =IDAssigned(A2)
' Purpose   : Find the color in the text and assign the Name of the person from the table to the right
'---------------------------------------------------------------------------------------
'
Public Function IDAssigned(CellRef As Range)
Dim cCell As Range
Dim strTestVal As String
Dim Bullpen As String
Dim varFindRef As Variant
Dim wks As Worksheet
Dim rngLookupRange  As Range
Dim SrchVals As Range
    Set wks = ThisWorkbook.Worksheets("Sheet1")
    'Dynamic Range for the Colors and Assigned map
    Set SrchVals = _
        wks.Range(Range("D2"), Range("D" & Rows.Count).End(xlUp))
    'Check if the Phrases is blank
    If Len(CellRef) = 0 Then
        IDAssigned = "No Match"
        Exit Function
    End If
'Loop through colors values
For Each cCell In SrchVals.Cells
   strTestVal = CStr(cCell.Value)
   If Len(CellRef.Value) <> 0 Then
      'List ref cell is not blank, so test the cell
      varFindRef = InStr(1, CellRef, strTestVal)
      If varFindRef > 0 Then
        Bullpen = cCell.Offset(0, 1).Value
        GoTo foundit
      End If
   End If
Next cCell
foundit:
    If Bullpen = "" Then
       IDAssigned = "No Match"
    Else
       IDAssigned = Bullpen
    End If
End Function


----------



## Gene Khalyapin

*Re: June/July 2008 Challenge of the Month*



VIJAYKUMAR SHETYE said:


> This is the best I could manage
> 
> =OFFSET(E1,MATCH(1,IF(SEARCH(D2:D4,A2,1)>0,1,0)),0,1,1)
> 
> Vijaykumar Shetye,
> India


 
Hi Vijaykumar,

You can make the formula a little shorter (remove IF() argument) and add some $ so you can stretch it down:

=OFFSET($E$1,MATCH(1,SEARCH($D$2:$D$10,A2),-1),0)

Ctrl+Shift+Enter


----------



## lettleman

*Re: June/July 2008 Challenge of the Month*

Well, nor nearly as slick as some of the ones above, but pretty expandable, gets the job done, and readable...I prefer UDFs because its easier to tell whats going on in the worksheet itself. You can fix the Redditch problem (or the ditchRed problem) by using some conditionals in the worksheet to see if the letter before or after the keyword in the phrase is a space.

The first function does the brunt of the work, but I also added a check for whitespace characters in the keywords (not just the phrases) that uses the second function posted below.



		Code:
__


Function searchUsingKeywordTable(haystackRef As Range, needleTable As Range, Optional toggle As Integer = 1) As Variant
   
   'Like the Search worksheet function but allows searching from multiple keywords. Keywords can be more than one word apiece and contain any text.
   
   'haystackRef is a single cell reference with text to be searched. Ex "A1"
   'needleTable is a range, such as "A1:A10", that includes the keywords column. Do NOT include column headers or the Assigned to Coulmn.
   
   'When toggle is:
      '1: function returns the first keyword found in the searched text, or "#NA" if no keyword not found
      '2: function returns the position of the first letter of the first keyword found in the searched text, or "#NA" if no keyword found
      'Default value for toggle is 1
      
   searchUsingKeywordTable = CVErr(xlErrNum)
  
   Dim haystack As String
   haystack = haystackRef.Value
   
   'Although not an issue in this challenge, we dont want capitalization to throw off the search function, so lets make everything the same case
   haystack = UCase(haystack)
  
   'Now we loop through each keyword, using the Instr fxn to see of any of the keywords are in the haystack
   'Note the use of the cleanerText function. Although not needed for this challenge, this function makes it so that cells in the keyword
   ' column that are blank, or contain only spaces or even other non-space ascii whitespace or nonprinting characters, will not be searched for
   Dim cll As Object
   Dim cllValue As String
   For Each cll In needleTable
      cllValue = cll.Value
      If InStr(1, haystack, UCase(trim(cllValue))) And cleanerText(cllValue, True, True, True) <> "" Then
         If toggle = 1 Then
            searchUsingKeywordTable = cllValue
         Else
            searchUsingKeywordTable = InStr(1, haystack, UCase(cllValue))
         End If
         Exit For
      End If
   Next cll

End Function




		Code:
__


Function cleanerText(text As String, Optional ConvertBreakingChars As Boolean = False, Optional RemoveNonPrintables As Boolean = False, Optional trimString As Boolean = False) As String
   
   'Replaces all nonbreaking whitespace characters with spaces
   'If ConvertBreakingChars is set to TRUE, also sets breaking whitespacecharacters to spaces (default is false)
   'If RemoveNonPrintables is set to TRUE, removes nonprinting characters (default is false)
   'If trimString is set to TRUE, trims spaces on both sides of string (default is false)
   
   'Add special characters to an array
   
   Dim Wspace() As String
   ReDim Wspace(1 To 6) As String
   
   Wspace(1) = Chr(9)
   Wspace(2) = Chr(0)
   Wspace(3) = Chr(1)
   Wspace(4) = Chr(2)
   Wspace(5) = Chr(3)
   Wspace(6) = Chr(160)
   
   If ConvertBreakingChars = True Then
      ReDim Preserve Wspace(1 To 8) As String
      Wspace(7) = Chr(10)
      Wspace(8) = Chr(13)
   End If
   
   'Loop through the array, replacing all wspace characters with spaces
   Dim i As Integer
   i = 1
   
   Do While i < (UBound(Wspace) + 1)
      Do While InStr(1, text, Wspace(i))
         text = Replace(text, Wspace(i), " ")
      Loop
      i = i + 1
   Loop
   
   If RemoveNonPrintables = True Then
      text = Application.WorksheetFunction.Clean(text)
   End If
   
   If trimString = True Then
      text = trim(text)
   End If
   
   cleanerText = text
   
End Function


----------



## soodaarti21

*Re: June/July 2008 Challenge of the Month*

visit http://www.mediafire.com/?otx11wz0jwy i have uploaded my answer without using VBA coding.


----------



## Derek Brown

*Re: June/July 2008 Challenge of the Month*

If I had realised earlier that the solution had to be 'posted' instead of emailing the workbook, I would have done this earlier.
I prefer the UDF solution that is likely to make sense to me in a few months time instead of a formula that is going to make my head ache.
My solution is:


		Code:
__


Function ReverseLOOKUP(rngCell As Range, rngTable As Range, lngColumn As Long) As String
Application.Volatile
Dim rng As Range
If ((lngColumn > rngTable.Columns.Count) Or (lngColumn < 1)) Then
    ReverseLOOKUP = "#REF!"
Else
    For Each rng In rngTable.Columns(1).Cells
        If InStr(1, rngCell.Value, rng.Value) > 0 Then
            ReverseLOOKUP = Cells(rng.Row, rng.Column + lngColumn - 1)
            Exit For
        End If
    Next rng
End If
Set rng = Nothing
End Function

and then, for example, in Cell B2 the formula would be:
=reverselookup(A2,$D$2:$E$10,2)


----------



## PaddyD

*Re: June/July 2008 Challenge of the Month*

soodaarti21,

Suggest you post your answer to the board - not sure that anyone's going to navigate to an unknown sits & challenge instructions were to post to this thread.


----------



## ajayssarode

*Re: June/July 2008 Challenge of the Month*

Dim i As Integer
Dim j As Integer
For i = 2 To 100
    For j = 2 To 100
        Cells(i, 8) = "=Search(D" & j & ", A" & i & ", 1)"
        If Not IsError(Cells(i, 8)) Then
            Cells(i, 9) = Cells(j, 4)
            Cells(i, 2) = Cells(j, 5)
            GoTo a
        End If

    Next

a: Next
Sheet1.Range("H:I").ClearContents


----------



## pjzamudio

*Re: June/July 2008 Challenge of the Month*

This is my first post (golf clap). 

I'm currently deployed to the Middle East and I am stuck in a non-flying desk job for a month, so this gives me a great escape until I get back to flying.

The code below also accounts for multiple people assigned to same "color" by concatenating " / " between multiple names. You probably don't need the declarations, but I'm old fashioned.



		Rich (BB code):
__


Sub subParseColor()
Dim iCompareCol As Integer
Dim iCompareRow As Integer
Dim iLookupTableCol As Integer
Dim iLookupTableRow As Integer
Dim strCompare As String
Dim strLookupTable As String
 
iCompareCol = 1
iCompareRow = 2
iLookupTableCol = 4
iLookupTableRow = 2
 
With ActiveSheet
   strCompare = .Cells(iCompareRow, iCompareCol).Value
   strLookupTable = .Cells(iLookupTableRow, iLookupTableCol).Value
   While strCompare <> "" 
      While strLookupTable <> "" 
         If (InStr(1, strCompare, strLookupTable)) Then _
            .Cells(iCompareRow, iCompareCol + 1).Value = _
              IIf(.Cells(iCompareRow, iCompareCol + 1).Value <> "", _
               .Cells(iCompareRow, iCompareCol + 1).Value & " / " & _
               .Cells(iLookupTableRow, iLookupTableCol + 1).Value, _
               .Cells(iLookupTableRow, iLookupTableCol + 1).Value)
         iLookupTableRow = iLookupTableRow + 1
         strLookupTable = .Cells(iLookupTableRow, iLookupTableCol).Value
      Wend
      iLookupTableRow = 2
      strLookupTable = .Cells(iLookupTableRow, iLookupTableCol).Value
      iCompareRow = iCompareRow + 1
      strCompare = .Cells(iCompareRow, iCompareCol).Value
   Wend 
 End With
End Sub


----------



## Fowmy

*Re: June/July 2008 Challenge of the Month*

1. Make the following Two defined Names (Fm & Key) & enter as an array formula by pressing (Ctrl+Shift+Enter).

FM =INDEX(Sheet1!$D$2:INDIRECT("$E$"&ROWS(Key)+1),MAX(IF(ISERROR(SEARCH(IF(CODE(TRIM(Key))=32,-1,TRIM        (Key)),Sheet1!A31)),-2,ROW(Key)-1)),2)

KEY =Sheet1!$D$2:INDIRECT("$d$"&MAX((LEN(Sheet1!$D$2:$D$634)<>0)*ROW(Sheet1!$D$2:$D$634)))

2. Type the following formula in cell b2 & copy down

=IF(ISERROR(Fm),"Color not found!",Fm)


----------



## Derek Brown

*Re: June/July 2008 Challenge of the Month*

An update to my solution of 9th July, with a change of function name to ReverseVLOOKUP, this includes more argument validation and the option to check the entire content of the cell.


		Code:
__


Function ReverseVLOOKUP(rngCell As Range, rngTable As Range, lngColumn As Long, _
    Optional blEntireCellContent As Boolean) As String
Application.Volatile
Dim rng As Range
Dim blEntireCell As Boolean
If ((lngColumn > rngTable.Columns.Count) Or (lngColumn < 1) Or _
    (rngCell.Columns.Count > 1) Or (rngCell.Rows.Count > 1)) Then
    ReverseVLOOKUP = "#REF!"
    Exit Function
End If
If IsMissing(blEntireCellContent) Then
    blEntireCell = False
Else
    blEntireCell = blEntireCellContent
End If
For Each rng In rngTable.Columns(1).Cells
    If blEntireCell Then
        If rngCell.Value = rng.Value Then
            ReverseVLOOKUP = Cells(rng.Row, rng.Column + lngColumn - 1)
            Exit For
        End If
    ElseIf InStr(1, rngCell.Value, rng.Value) > 0 Then
        ReverseVLOOKUP = Cells(rng.Row, rng.Column + lngColumn - 1)
        Exit For
    End If
Next rng
Set rng = Nothing
End Function

The first argument is the lookup value, the second is the table array, the third is the column to return and the new argument is a boolean (true or false) to indicate whether the entire cell is to match.


----------



## Derek Brown

*Re: June/July 2008 Challenge of the Month*

Perhaps I should add that if the last argument is set to TRUE, the function will perform in the same way as VLOOKUP. However, it is possible to set that last argument to a specific cell reference and then be able to 'switch' between the two types of result by just changing the value of one cell.


----------



## stanleydgromjr

*Re: June/July 2008 Challenge of the Month*

My last try (shorter code).

Thank you Daniel Ferry.


Thanks, had a lot of fun with this.



		Code:
__


Option Explicit
Sub ColorAssignedTo()
    Dim LRA&, LRD&
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
        LRA& = Cells(Rows.Count, 1).End(xlUp).Row
        LRD& = Cells(Rows.Count, 4).End(xlUp).Row
        Range("B2:B" & LRA&).FormulaR1C1 = "=LOOKUP(32767,FIND(R2C[2]:R" & LRD& & "C[2],RC[-1]),R2C[3]:R" & LRD& & "C[3])"
        .CutCopyMode = False
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
End Sub



Have a great day,
Stan


----------



## bosco_yip

*Re: June/July 2008 Challenge of the Month*

1]  =lookup(2,1/find(d$2:d$10,a2),e$2:e$10)

2]  =lookup(0,1/find(d$2:d$10,a2)-1,e$2:e$10)

3]  {=index($e$2:$e$10,match(1,--isnumber(find($d$2:$d$10,a2)),0),0)}


----------



## lostramc

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)



Could someone explain how this works?
I have tried dissecting it and looking in Excels help file for the Lookup function but still can't figure it out.


----------



## schielrn

*Re: June/July 2008 Challenge of the Month*



lostramc said:


> Could someone explain how this works?
> I have tried dissecting it and looking in Excels help file for the Lookup function but still can't figure it out.


See Richard's explanation here:

http://www.mrexcel.com/forum/showpost.php?p=1599318&postcount=34

Hope that helps.


----------



## EugeneCarter

*Re: June/July 2008 Challenge of the Month*

I know i'm late, and there's a billion posts, but I just found this "challenge of the month" and I thought I'd throw what I came up with, and my apologies if someone already posted this.

=INDEX($E$2:$E$10,SUMPRODUCT(--NOT(ISERROR(SEARCH($D$2:$D$10,$A2)))*(ROW($D$2:$D$10)-1)))


----------



## andrewman

*Re: June/July 2008 Challenge of the Month*

Please give me a chance to read my code.  Thanks!

Option Explicit
Private Function Vlookups(Key As Variant, Area As Range, Col As Integer, m As Boolean) As Variant
Dim SKey As Variant
SKey = S(Key, Area)
If SKey = "" Then
Vlookups = "Not yet assigned"
Else
Vlookups = Application.WorksheetFunction.VLookup(SKey, Area, Col, m)
End If
End Function

Private Function S(Key As Variant, ByVal list As Range) As Variant
Dim n As Variant
Set list = list.Resize(list.Rows.Count, 1)

For Each n In list
If InStr(1, Key, n.Value, vbTextCompare) > 0 Then
S = n.Value
Exit For
End If
Next n

End Function



Andrew Man
From Hong Kong


----------



## andrewman

*Re: June/July 2008 Challenge of the Month*



jindon said:


> How about ?
> UDF
> =VLookLike(A2, $E$2:$E$10)
> 
> 
> Code:
> __
> 
> 
> Function VLookLike(txt As Variant, rng As Range) As Variant
> Dim myPtn As String
> myPtn = "(" & Join(WorksheetFunction.Transpose(rng.Columns(1).Value),"|") & ")"
> With CreateObject("VBScript.RegExp")
> .Pattern = myPtn
> If .test(txt.Value) Then myMatch = .execute(txt.Value)(0)
> End With
> VLookLike = rng.Columns(2).Cells(WorksheetFunction.Match(myMatch,rng.Columns(1),0)).Value
> End Function


 
After I posted my answer, I read all the code. I only like the code from Jindon. I am not fully understand how it work. But, I can you his method to solve some of my old problems now. 

Moreover, I think we should be more creative to use the code. I have seen a lot of code lookup & index ....... Most of the code logic is the same, I think it had already post in the another thread which I seen a lots here!! We should read more and then create our own code.

Jindon, Nice to meet you here! I guess you are the best.

I hope you can give me of your email. Thus, we can discuss more about the Excel problems from user.

Regards,

Andrew Man
From Hong Kong


----------



## andrewman

*Re: June/July 2008 Challenge of the Month*

VBA can use the Regular Expression which just like OpenOffice worked.

Jindon has demonstrated the method how the use the Regular Expression in VBA.

Do you think is suitable?

Andrew Man
From Hong Kong


----------



## andrewman

*Re: June/July 2008 Challenge of the Month*

<TABLE class=tborder id=post1626550 cellSpacing=0 cellPadding=6 width="100%" align=center border=0><TBODY><TR vAlign=top><TD class=alt1 id=td_post_1626550 style="BORDER-RIGHT: #ffffff 1px solid">VBA can use the Regular Expression which just like OpenOffice worked.

Jindon has demonstrated the method how to use the Regular Expression in VBA.

Do you think is suitable?

Andrew Man
From Hong Kong
<!-- / message --></TD></TR><TR><TD class=alt2 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid">
	

	
	
		
		

		
			





   </TD><TD class=alt1 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 0px solid; BORDER-BOTTOM: #ffffff 1px solid" align=right><!-- controls --></TD></TR></TBODY></TABLE>


----------



## kevinmintz006

*Re: June/July 2008 Challenge of the Month*

sorry i am late, i am a new user as of today = ).

here's my solution (macro code):


Sub Solution()
'
' Solution Macro
' Macro recorded 7/17/2008 by e363131
'
'
   Dim i As Long, strx As String, stry As String, strz As String
    i = 2
    Range("A:A").Select

     Columns("A:A").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("B:B").Select
    ActiveSheet.Paste

    For i = 1 To 10


    strx = "D" & i
    'MsgBox (strx)
    stry = Range(strx).Value
    'MsgBox (stry)
    strz = "~*" & stry & "~*"
    Selection.Replace What:="*" & Range(strx).Value & "*", Replacement:="=E" & i, LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

    Next
End Sub



It's good to be partof the community.


----------



## jimnaff

*Re: June/July 2008 Challenge of the Month*

I know it's past the deadline, but I thought I would offer this:

Public Function AssignTo(Phrase As String, KeyWordList As Range) As String
    Dim i As Integer
    For i = 1 To KeyWordList.Rows.Count
        If InStr(1, Phrase, KeyWordList(i, 1)) > 0 Then
            AssignTo = KeyWordList(i, 2)
            Exit For
        End If
    Next i
End Function


----------



## jindon

*Re: June/July 2008 Challenge of the Month*



andrewman said:


> VBA can use the Regular Expression which just like OpenOffice worked.
> 
> Jindon has demonstrated the method how the use the Regular Expression in VBA.
> 
> Do you think is suitable?
> 
> Andrew Man
> From Hong Kong


 
Andrew,

I think what Regular Expression does can be done by vba built-in functions anyhow.
However the length of the code will be much shorter when it is used sometime.


----------



## andrewman

*Re: June/July 2008 Challenge of the Month*

Yes, the code will be shorter.

But, it will be a limitation in the length of the String for searching.

Regards,


----------



## jindon

*Re: June/July 2008 Challenge of the Month*



andrewman said:


> Yes, the code will be shorter.
> 
> But, it will be a limitation in the length of the String for searching.
> 
> Regards,


What limitation?


----------



## andrewman

*Re: June/July 2008 Challenge of the Month*

the length of the String for searching


----------



## bosco_yip

*Re: June/July 2008 Challenge of the Month*



bosco_yip said:


> 1]  =lookup(2,1/find(d$2:d$10,a2),e$2:e$10)
> 
> 2]  =lookup(0,1/find(d$2:d$10,a2)-1,e$2:e$10)
> 
> 3]  {=index($e$2:$e$10,match(1,--isnumber(find($d$2:$d$10,a2)),0),0)}



Add 2 more formula :

4]  =LOOKUP(0,-FIND(D$2:D$10,A2),E$2:E$10)

5]  =LOOKUP(0,FIND(D$2:D$10,A2)-1,E$2:E$10)


----------



## U.Surender

*Re: June/July 2008 Challenge of the Month*

I am pretty new to the Excel game so any help would be great!! Why doesn't this work??

=IF(ISERR(SEARCH("blue",A2))=FALSE,"Joe",IF(ISERR(SEARCH("red",A2))=FALSE,"Bob",IF(ISERR(SEARCH("yellow",A2))=FALSE,"Mary",IF(ISERR(SEARCH("pink",A2))=FALSE,"Fred",IF(ISERR(SEARCH("orange",A2))=FALSE,"Ralph",IF(ISERR(SEARCH("brown",A2))=FALSE,"Lora",33))))))


----------



## EugeneCarter

*Re: June/July 2008 Challenge of the Month*

1) doesn't use the lookup table (you manually entered lookup values)
2) not scalable (excel can only support so many recursive IFs)


----------



## U.Surender

*Re: June/July 2008 Challenge of the Month*



EugeneCarter said:


> 1) doesn't use the lookup table (you manually entered lookup values)
> 2) not scalable (excel can only support so many recursive IFs)



Oh, I didnt know about the If function Limits, THANKS!


----------



## U.Surender

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)



I've been try to understand why this works by looking at the descriptions of the functions used.  I don't quite understand why the Search() function works within the Lookup() function but not by itself....can anyone help me see why this is so?


----------



## kevinmintz006

*Re: June/July 2008 Challenge of the Month*



kevinmintz006 said:


> sorry i am late, i am a new user as of today = ).
> 
> here's my solution (macro code):
> 
> 
> Sub Solution()
> '
> ' Solution Macro
> ' Macro recorded 7/17/2008 by e363131
> '
> '
> Dim i As Long, strx As String, stry As String, strz As String
> i = 2
> Range("A:A").Select
> 
> Columns("A:A").Select
> Application.CutCopyMode = False
> Selection.Copy
> Columns("B:B").Select
> ActiveSheet.Paste
> 
> For i = 1 To 10
> 
> 
> strx = "D" & i
> 'MsgBox (strx)
> stry = Range(strx).Value
> 'MsgBox (stry)
> strz = "~*" & stry & "~*"
> Selection.Replace What:="*" & Range(strx).Value & "*", Replacement:="=E" & i, LookAt:=xlPart, _
> SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
> ReplaceFormat:=False
> 
> Next
> End Sub
> 
> 
> 
> It's good to be partof the community.


 ---------------------------------------------------
I'd like to post this edit to my original formula. (Just so you wouldn't have to change the If statement when you add more lines to the lookup table)
-----------------------------------------------------
Sub Solution()
   Dim i As Long, strx As String, stry As String, strz As String
    i = 2
    Range("A:A").Select
    Columns("A:A").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("B:B").Select
    ActiveSheet.Paste

    intRow = Range("D:D").SpecialCells(xlCellTypeConstants).Count
    For i = 1 To intRow
    strx = "D" & i
    stry = Range(strx).Value
    strz = "~*" & stry & "~*"
    Selection.Replace What:="*" & Range(strx).Value & "*", Replacement:="=E" & i, LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Next
End Sub
-------------------------------------------------------

what do you think?


----------



## EugeneCarter

*Re: June/July 2008 Challenge of the Month*

This


kevinmintz006 said:


> Range("A:A").Select
> Columns("A:A").Select
> Application.CutCopyMode = False
> Selection.Copy
> Columns("B:B").Select
> ActiveSheet.Paste
> 
> what do you think?


Could be this:
Range("B:B").FormulaR1C1 = Range("A:A").FormulaR1C1
or
Range("B:B").Formula = Range("A:A").Formula
or
Range("B:B").Value= Range("A:A").Value
depending on your preference about values, absolute references, etc.


----------



## EugeneCarter

*Re: June/July 2008 Challenge of the Month*



kevinmintz006 said:


> ---------------------------------------------------
> I'd like to post this edit to my original formula. (Just so you wouldn't have to change the If statement when you add more lines to the lookup table)
> -----------------------------------------------------
> 
> what do you think?


 
One flaw that I see with this, is that it only works well if none of lookup values are similar to others.  For example if one is blue and another is blue-green


----------



## bbotzong

*Re: June/July 2008 Challenge of the Month*

here's a function. useage is as follows. In cell B2 enter formula =sLookup(A2,$D$2:$D$10,2) which calls the sLookup function as follows:

Function sLookup(txtInput As String, rngList As Range, wIndex As Integer)
   Dim wRow As Integer
   Dim wCol As Integer

   ' find how many keywords in rngList

   wRow = 1
   wList = rngList

   For Each cell In rngList
      If InStr(1, txtInput, cell) > 0 Then
         wRow = cell.Row
         wCol = cell.Column
         sLookup = Cells(wRow, wCol + wIndex - 1)
         Exit Function
      End If
   Next 'cell
End Function


----------



## Rhino_Dance

*I didn't understand it either!*

I'm new here and really appreciate this forum. Thanks to everyone for your... brilliance. I realize I have so much more to leverage in xl. 

Ok, I'm writing this post for anyone like me- who really scratched their heads over this one. Perhaps there are a few? I read Richard's explanation which got me halfway there but couldn't pull off the juggling necessary. Thought I'd explain how I finally understood it to those who may be having my experience. The formula to be interpreted is:

=LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)

First, the SEARCH function has the argumants _backward_ from what I'm used to. Usually with the SEARCH /FIND function I'm looking for 1 thing in an ocean of things. In this case an ocean of things are looking for one thing and returning 9 results. I kept thinking that a SEARCH involving 'A2' must only return one number. I was also visually thrown off by the lack of Braces {} reminding me of array formula.

So, the SEARCH function returns an array of 9 results each corresponding to the colors in the order they appear. The array always has 8 errors and one valid number like this:

#VALUE!
#VALUE!
#VALUE!
12
#VALUE!
#VALUE!
#VALUE!
#VALUE!
#VALUE!

The lookup function will always match the huge number (32,767) to the one row with the valid number- row 4 in this case- and that is of course the row of the matching color. The Lookup function then goes 4 rows down in column 'E' to find the correct person's name.

I realize this is known to most but though I'd describe the formula in the way it finally came to me. And I agree the formula is beautiful in its simplicity.

My formula was pretty standard. I added ascending numbers next to the color/name table though. 

={INDEX(Color_Tab,SUM(IF(ISERROR(FIND(Colors,$A2,1)),0,Color_Nums)),3))

Cheers


----------



## MIKE617

*Re: June/July 2008 Challenge of the Month*

It works, but I don't understand how.  References to LOOKUP don't mention placing a value in front of the lookup_value. Yes, I'm am a beginner, looking for understanding. 
I placed only the SEARCH portion of the equation into each cell in col. B, no array. The result was only the cells of the same row were evaluated. So I made each eq. in col. B an array.  But, only the first cell "D2" was evaluated against each phrase. Cells B2 through B4 returned values. Getting closer.  When using the full eq, I played with the value 2^15, when it is = or > to the value returned by the SEARCH eq., it returns the correct value from col.E. Need a 'nudge' understanding how the first number in the LOOKUP creates an array. Thanks.


----------



## MIKE617

*Re: June/July 2008 Challenge of the Month*



MIKE617 said:


> It works, but I don't understand how.  References to LOOKUP don't mention placing a value in front of the lookup_value. Yes, I'm am a beginner, looking for understanding.
> I placed only the SEARCH portion of the equation into each cell in col. B, no array. The result was only the cells of the same row were evaluated. So I made each eq. in col. B an array.  But, only the first cell "D2" was evaluated against each phrase. Cells B2 through B4 returned values. Getting closer.  When using the full eq, I played with the value 2^15, when it is = or > to the value returned by the SEARCH eq., it returns the correct value from col.E. Need a 'nudge' understanding how the first number in the LOOKUP creates an array. Thanks.


Thanks Rhino Dance!
Sorry all, should have read previous posts.


----------



## Rhino_Dance

*Re: June/July 2008 Challenge of the Month*

Mike,

You wrote:
_*References to LOOKUP don't mention placing a value in front of the lookup_value.*_

There is no number in front of the lookup value. The lookup value is 2^15 (2 raised to the 15th power) which evaluates to a number near 32,000. 

You are right that the below formula returns one result in the cell in which it is written. 

{=SEARCH(D$2:D$10,A2)}

But now, highlight the whole formula up in the formula bar and then hit [F9]. [F9] calculates whatever is highlighted. You will then see the 9 array values in the formula bar which will look something like this: 

{14;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!}

Also to answer your question, the first number in a Lookup is a repeating array of the same value equal to the same number of values that it is being compared to. 

Take a Lookup that looks for 'a' in a lookup array of 'b', 'c' 'd'. It does 3 tests of 'a' against the three values. Like this:
'a' vs 'b'
'a' vs 'c'
'a' vs 'd'

So there's 3 repeating 'a' s. This is the same as 9 repeating 2^15 's in the original equation. 

Maybe also worth pointing out is that although the Lookup formula processes via arrays (multiple values) it does only return one number. And that comes back to square with intuition. Hope this is all correct and hope it helps.


----------



## Jonmo1

*Re: June/July 2008 Challenge of the Month*

OK, so this is the first Challenge I've participated in.  When/How do we know the results?


----------



## kevinmintz006

*Re: June/July 2008 Challenge of the Month*

-------------------------------------
Sub Solution()
Dim i As Long, strx As String,
i = 2

Columns("A:A").Select
Application.CutCopyMode = False
Selection.Copy
Columns("B:B").Select
ActiveSheet.Paste

intRow = Range("D:D").SpecialCells(xlCellTypeConstants).Count
For i = 1 To intRow
strx = "D" & i

Selection.Replace What:="* " & Range(strx).Value & " *", Replacement:="=E" & i, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next
End Sub
-------------------------
***Deleted unnecessary code. sticking with copy and paste.

Who likes blue-green anymore? Turqoise is way better. lol. j/k
It would still work as long as the blue-green is closer to the top of the list than the blue or the green. You would just have to impose that restriction on the person typing the list. 

Another way to fix this would be to write code to add to the beginning of the macro to first sort the Keywords by character length from longest to shortest before applying the rest (to ensure blue-green shows up first). [Or adding a reverse counter that counts down from the max charater length to the shortest and finding matches from longest to shortest]

But for all intensive purposes, this way is quicker and works perfectly fine as long as you don't have "blue-green."

Thanks for the comments Eugene.


----------



## EugeneCarter

*Re: June/July 2008 Challenge of the Month*



kevinmintz006 said:


> -------------------------------------
> ...
> ...
> Columns("A:A").Select
> Application.CutCopyMode = False
> Selection.Copy
> Columns("B:B").Select
> ActiveSheet.Paste
> ...
> ...
> -------------------------
> ***Deleted unnecessary code. sticking with copy and paste.
> ...
> ...
> 
> Another way to fix this would be to write code to add to the beginning of the macro to first sort the Keywords by character length from longest to shortest before applying the rest (to ensure blue-green shows up first). [Or adding a reverse counter that counts down from the max charater length to the shortest and finding matches from longest to shortest]
> 
> But for all intensive purposes, this way is quicker and works perfectly fine as long as you don't have "blue-green."
> 
> Thanks for the comments Eugene.


 
No Prob. Question though, can't you replace


		Code:
__


Columns("A:A").Select
Application.CutCopyMode = False
Selection.Copy
Columns("B:B").Select
ActiveSheet.Paste

with


		Code:
__


Columns("B:B").Value = Columns("A:A").Value

?
I like the idea of running from longest to shortest.. that'd fix that blue-green  smart guy...


----------



## smartchap

*Re: June/July 2008 Challenge of the Month*

I have tried it with VB6 and it works fine. Here is a macro for this:

Sub Assign()
    For i = 2 To 10
        Colorname = Cells(i, "D").Value
        Name = Cells(i, "E").Value
        For j = 2 To 25
            colorexist = InStr(1, Cells(j, "A").Value, Colorname)
            If colorexist <> 0 Then
                Cells(j, "B").Value = Name & ": " & Cells(j, "A").Value
            End If
        Next
    Next
End Sub


----------



## Rhino_Dance

*Re: June/July 2008 Challenge of the Month*

Good, solid solution Smartchap. Very direct.


----------



## smartchap

*Re: June/July 2008 Challenge of the Month*

Thanks Rhino_Dance for the compliments. The code can be generalized if number of rows in any column increases or changes so that number of filled rows in that column is read and used as range. Thanks once again.


----------



## smartchap

*Re: June/July 2008 Challenge of the Month*

To make it general so that may take care of number of entries in columns A, D & E the modified code is as below:

Sub Assign()
    For i = 2 To Range("D2", Range("D2").End(xlDown)).Count + 1
        Colorname = Cells(i, "D").Value
        Name = Cells(i, "E").Value
        For j = 2 To Range("A2", Range("A2").End(xlDown)).Count + 1
            colorexist = InStr(1, Cells(j, "A").Value, Colorname)
            If colorexist <> 0 Then
                Cells(j, "B").Value = Name & ": " & Cells(j, "A").Value
            End If
        Next
    Next
End Sub

+1 is added because data starts from second row in A & D columns.


----------



## smartchap

*Re: June/July 2008 Challenge of the Month*

Following code will take care of sentences like:
My friend red's shirt is blue
and
the country Redditch in Australia is very beautful

and check the first colour name in the sentence.


Sub Assign()
    For i = 2 To Range("D2", Range("D2").End(xlDown)).Count + 1
        Colorname = LCase$(Cells(i, "D").Value)
        Name = Cells(i, "E").Value
        For j = 2 To Range("A2", Range("A2").End(xlDown)).Count + 1
            colorexist = InStr(1, LCase$(Cells(j, "A").Value), Colorname)
            If colorexist <> 0 Then
                Cells(j, "B").Value = Name & ": " & Cells(j, "A").Value
            End If
        Next
    Next
End Sub


----------



## smartchap

*Re: June/July 2008 Challenge of the Month*

Modified code for checking all color names and assigning them is as follows:

Sub Assign3()
    For i = 2 To Range("D2", Range("D2").End(xlDown)).Count + 1
        Colorname = LCase$(Cells(i, "D").Value)
        Name = Cells(i, "E").Value
        For j = 2 To Range("A2", Range("A2").End(xlDown)).Count + 1
            colorexist = InStr(1, LCase$(Cells(j, "A").Value), Colorname)
            If colorexist <> 0 Then
                If Cells(j, "B").Value = "" Then
                    Cells(j, "B").Value = Name & ": " & Cells(j, "A").Value
                Else
                    Cells(j, "B").Value = Cells(j, "B").Value + Chr(10) + Name & ": " & Cells(j, "A").Value
                End If
            End If
        Next
    Next
End Sub


----------



## AASkehan

*Re: June/July 2008 Challenge of the Month*

I have a simple formula based solution for those not versed in VBA or arrays.

I started by creating a table (F2:N26) to identify which color was in the Phrase by 
- Taking the list of colors and transposing them as titles. (F2:N2)
- The used the "find" function to idenitfy the color. 
- Then added the ISERROR trap to remove any #value returns.
Example formula to evaluate the phrase in A3 against Blue (F2)
'=IF(ISERROR(FIND(F$2,$A3)),"",F$2)

2nd formula is to place the names in column B 
by 'CLEAN' ing the concatenated row of values to obtain just the color, then do a simple VLOOKUP to return the correct name.
<TABLE style="WIDTH: 340pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=452 border=0 x:str><COLGROUP><COL style="WIDTH: 224pt; mso-width-source: userset; mso-width-alt: 12714" width=298><COL style="WIDTH: 41pt; mso-width-source: userset; mso-width-alt: 2304" width=54><COL style="WIDTH: 53pt; mso-width-source: userset; mso-width-alt: 3029" width=71><COL style="WIDTH: 22pt; mso-width-source: userset; mso-width-alt: 1237" width=29><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD class=xl65 style="BORDER-RIGHT: #c0c0c0; BORDER-TOP: #c0c0c0; BORDER-LEFT: #c0c0c0; WIDTH: 340pt; BORDER-BOTTOM: #c0c0c0; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" width=452 colSpan=4 height=17 x:str="'=VLOOKUP(CLEAN(F3&G3&H3&I3&J3&K3&L3&M3&N3),$C$3:$D$11,2,FALSE)">=VLOOKUP(CLEAN(F3&G3&H3&I3&J3&K3&L3&M3&N3),$C$3:$D$11,2,FALSE)</TD></TR></TBODY></TABLE>
This method allows the rows to be rearranged, but not to have multiple colors in one Phrase.


----------



## smartchap

*Re: June/July 2008 Challenge of the Month*

Dear jindon

On page 6 I think your formula needs to be corrected as

=VLookLike(A2, $D$2:$E$10)

and it works.


----------



## gardnertoo

*Re: June/July 2008 Challenge of the Month*

While Barry's solution seems to be far and away the best formula-based entry, I have another solution nobody else has posted:


		Code:
__


=INDEX(E$2:E$10,MATCH(INDEX(D$2:D$10,MATCH(MIN(LEN(SUBSTITUTE(A2,D$2:D$10,""))),(LEN(SUBSTITUTE(A2,D$2:D$10,""))),0)),D$2:D$10,0))


Not as clean, and it gets different results when a second color is added.  Just thought I would toss in my two bits.  

I didn't know until this challenge that the LOOKUP function would work against an array containing error values.  My LEN(SUBSTITUTE array contains all numerical values for the INDEX(MATCH to work on.  Good to know there's a better way.


----------



## Papa Omaha

*Re: June/July 2008 Challenge of the Month*

I'm new to the VB/computer programming thing...judging from the entries, I imagine I could have done this 10 times more efficiently (if I knew how). I'm learning a ton though!!! 

Public Function colorfun(x As String)
Dim phraselettercount As Integer
Dim keyword_assignedto(9, 2) As String
Dim col As Integer
Dim wordcount As Integer
Dim wordstart As Integer
Dim rollingword As String
phraselettercount = Len(x)
wordstart = 1
col = 1
row1 = 1
x = Trim(x)
For i = 1 To 18
    If i <= 9 Then
    keyword_assignedto(i, col) = Range("D" & i + 1).Value
    Else
        If col = 1 Then
        col = col + 1
        End If
    keyword_assignedto(i - 9, col) = Range("E" & i - 9 + 1).Value
    End If
Next i
col = 1
For Z = 1 To phraselettercount + 1
    If Mid(Trim(x), wordstart, 1) <> " " And wordstart < Len(x) + 1 Then
        rollingword = rollingword & Mid(x, wordstart, 1)
        wordstart = wordstart + 1
    Else
        For p = 1 To 9
            If rollingword = keyword_assignedto(p, col) Then
            colorfun = keyword_assignedto(p, col + 1)
            End If            
        Next p
    wordstart = wordstart + 1
    rollingword = ""
    End If
Next Z
End Function


----------



## robind21283

*Re: June/July 2008 Challenge of the Month*

I can't seem to get this formula to work if I add to the list of colors since its locked.  Is there anyway to make this dynamic?  

Otherwise, this is FABULOUS!


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Hi

Which formula are you using and what do you mean when you say "it is locked"?


----------



## robind21283

*Re: June/July 2008 Challenge of the Month*

Apparently, I prematurely hit send or thought everyone was psychic...

=LOOKUP(2^15,SEARCH($D$2:$D$10,A2),$E$2:$E$10)

And the cell references are frozen/locked (by the $)


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

I see. Well, you could make your list of colors a Dynamic Named Range which will expand and contract as you add to them, then reference that in the formula instead of the specific range.  See details of DNRs here:

http://www.contextures.com/xlNames01.html#Dynamic


----------



## robind21283

*Re: June/July 2008 Challenge of the Month*

When I select the whole row as a DNR, and put the names into the formula, I get a 0 result.


----------



## cornflakegirl

*Re: June/July 2008 Challenge of the Month*

What formula are you using to create the DNR?


----------



## robind21283

*Re: June/July 2008 Challenge of the Month*

=OFFSET(Sheet1!$D$2,0,0,COUNTA(Sheet1!D:D),1)


----------



## cornflakegirl

*Re: June/July 2008 Challenge of the Month*

Do you have a header in D1? If so, your COUNTA will include this row, so your range will be 1 row bigger than needed, and include a blank row at the bottom.


----------



## robind21283

*Re: June/July 2008 Challenge of the Month*

Is that why I'm getting a 0 result?  It doesn't seem like that would matter (for this particular example)


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Yes, it will end up returning the empty row (which Excel will interpet as having a value of zero).


----------



## robind21283

*Re: June/July 2008 Challenge of the Month*

So, am I better off deleting the header, or adding a -1 to my formula, or something else all together?

Thanks for all your help!


----------



## cornflakegirl

*Re: June/July 2008 Challenge of the Month*

Change the COUNTA range?


----------



## robind21283

*Re: June/July 2008 Challenge of the Month*

I got it to work using CountA(Sheet1!$D:$D)-1

If I change the range, then I would have to pick some arbitrary place for the list to end no?

Thanks!


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

You've done exactly the right thing.  You could have changed the range to start at D2 but you are rthen correct that you need to choose an arbitrary place to end the range (altho this could be D65536 if on xl2003 or below).


----------



## cornflakegirl

*Re: June/July 2008 Challenge of the Month*

Just make sure that no-one deletes the header


----------



## pma

*Re: June/July 2008 Challenge of the Month*

I pasted =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)  into b2:b25.  I then entered a different phrase including one of the colors into a26.  When I hit enter the formula from b25 was copied down to b26, which was blank, automatically.  I don't see any macros at work.  What's going on here?


----------



## barry houdini

*Re: June/July 2008 Challenge of the Month*

Hello pma, welcome to MrExcel. 

This is an Excel feature (certainly in 2003), see this from Excel [2003] Help. See red highlighted section

<TABLE class=OTbl cellSpacing=0 cellPadding=0 width="100%"><TBODY><TR><TD class=cdOTATtl width="100%">Extend formats and formulas to additional rows </TD><TD style="PADDING-RIGHT: 0px; PADDING-LEFT: 12px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"></TD><TR><TD class=ACB style="PADDING-RIGHT: 12px; PADDING-LEFT: 12px; PADDING-BOTTOM: 10px; PADDING-TOP: 10px" width="100%" colSpan=3><!-- defs in --><!-- META NAME="lcid" CONTENT="1033" -->By default, Microsoft Excel automatically formats new data that you type at the end of a range to match the preceding rows. Excel also automatically copies formulas that have been repeated in the preceding rows and extends them to additional rows.
*Note*  In order to be extended to new rows in the range, the formats and formulas must appear in at least three of the five preceding rows. 
You can turn this option off (or back on again) at any time:

On the *Tools* menu, click *Options*.
On the *Edit* tab, clear the *Extend data range formats and formulas* check box to turn automatic formatting off. To turn automatic formatting back on again, select the *Extend data range formats and formulas* check box.
<META content=03/24/2005 name=MajorRevDate><META content=08/15/2003 name=CreationDate><!--@@FEEDBACKWIZ@@--></TD></TR></TBODY></TABLE>


----------



## bridgesm

*Re: June/July 2008 Challenge of the Month*

I know I'm a few months too late, but I just checked the board for the first time in ages (I was bored). I had a go, and then saw everyone else's entries. But here's my sorrt attempt:

Sub theChallenge()

Dim countKeywords As Integer
Dim countPhrases As Integer

Dim i As Integer
Dim j As Integer

Dim theWords
Dim thePhrases

countKeywords = Range(Cells(2, 4), Cells(2, 4).End(xlDown)).Rows.count
countPhrases = Range(Cells(2, 1), Cells(2, 1).End(xlDown)).Rows.count

ReDim theWords(countKeywords, 2) As Variant
ReDim thePhrases(countPhrases) As String

Worksheets("Sheet1").Select

For i = 1 To countPhrases
    thePhrases(i) = Cells(i + 1, 1)
Next i

For i = 1 To countKeywords
For j = 1 To 2

    theWords(i, j) = Cells(i + 1, j + 3)

Next j
Next i


For i = 1 To countPhrases
For j = 1 To countKeywords
    If InStr(1, thePhrases(i), theWords(j, 1), 1) > 0 Then
    Cells(i + 1, 2) = theWords(j, 2)
    End If
Next j
Next i

End Sub


----------



## Bidyut_Saha

*Re: June/July 2008 Challenge of the Month*

Sub RoundedRectangle1_Click()

Dim r1 As Range, r2 As Range
Worksheets("Sheet1").Activate
Set r1 = Range("A2:B25")
Set r2 = Range("D2:E10")

Dim i As Integer, j As Integer
For i = 1 To 24
    For j = 1 To 9
        If InStrRev(r1.Cells(i, 1).Value, r2.Cells(j, 1).Value) > 0 Then
            r1.Cells(i, 2).Value = r2(j, 2).Value
        End If
    Next
Next

End Sub


----------



## KaranVBExpert

*Re: June/July 2008 Challenge of the Month*

I think I am a little late in submitting the solution to the challenge. But, better late than never.

Hoping to solve tougher challenges in future 

Sub mrexcelchallengejuly()

Dim lastrowcolmnA As Integer
Dim lastrowcolmnD As Integer

lastrowcolmnA = ActiveSheet.Range("A65536").End(xlUp).Row
lastrowcolmnD = ActiveSheet.Range("D65536").End(xlUp).Row

For j = 2 To lastrowcolmnA
    If Cells(j, 1).Value <> "" Then
        For i = 2 To lastrowcolmnD
            If Cells(i, 4).Value <> "" Then
                If InStr(1, Cells(j, 1).Value, Cells(i, 4).Value, vbTextCompare) > 0 Then
                    Cells(j, 2).Value = Cells(i, 5).Value
                End If
            End If
        Next
    End If
Next

MsgBox ("Process completed. " & Chr(10) & Chr(10) & "Please send me my prize ")

End Sub


----------



## edttoma

*Re: June/July 2008 Challenge of the Month*

A late suggestion...

Function Assigned(sColourful As String, AssignColourTo As Range) As String
'This function handles several colours (you never know)
'Try "Rainbow red orange yellow green blue indigo green magenta purple"!
'Formula e.g.: =Assigned(A2;$D2$:$E10)
Dim sSplit As Variant
On Error Resume Next
'Remove charcter (160) and loop over all words in the text
For Each sSplit In Split(Replace(sColourful, Chr(160), ""))
'Use the VLOOKUP workhorse...and append the persons to the function
Assigned = Assigned & " " & WorksheetFunction.VLookup(sSplit, AssignColourTo, 2, False)
Next sSplit
End Function


----------



## jules1970

*Re: June/July 2008 Challenge of the Month*

Just a little late, but wanted to share my approach:
Implementing regular expressions in VBA:

Private Function RegExpMatch(ByVal Cadena As String, ByVal PatronBusqueda As String, Optional IgnorarMayusculaMinuscula As Boolean = True, Optional Multilinea As Boolean = False) As String()

    Dim re As New RegExp
    Dim mMatches As MatchCollection
    Dim mMatch As Match
    Dim resultados() As String
    Dim i As Integer

    re.Pattern = PatronBusqueda
    re.Global = True
    re.IgnoreCase = IgnorarMayusculaMinuscula
    re.MultiLine = Multilinea

    Set mMatches = re.Execute(Cadena)
    If mMatches.Count > 0 Then
        ReDim resultados(0 To mMatches.Count - 1)
        For i = 0 To mMatches.Count - 1
            resultados(i) = mMatches(i).Value
        Next
        RegExpMatch = resultados
    Else
        ReDim resultados(-1 To -1)
        resultados(-1) = ""
        RegExpMatch = resultados
    End If

End Function

Public Function RegExpEncontrar( _
    ByVal Cadena As String, _
    ByVal PatronBusqueda As String, _
    Optional NumeroCoincidencia As Integer = 1, _
    Optional IgnorarMayusculaMinuscula As Boolean = True, _
    Optional Multilinea As Boolean = False) As String

    Dim resultados() As String
    Dim i As Integer
    resultados = RegExpMatch(Cadena, PatronBusqueda, IgnorarMayusculaMinuscula, Multilinea)
    i = NumeroCoincidencia - 1
    If i >= 0 And i <= UBound(resultados) Then
        RegExpEncontrar = resultados(i)
    Else
        RegExpEncontrar = ""
    End If

End Function

The solution is quite easy

Cell E12=blue|red|yellow|pink
Formula= =regexpencontrar(A2,$E$12)

Will return the text that matches the pattern.


 <table style="border-collapse: collapse; width: 270pt;" width="359" border="0" cellpadding="0" cellspacing="0"><col style="width: 130pt;" width="173">  <col style="width: 140pt;" width="186">  <tbody><tr style="height: 15pt;" height="20">   <td style="height: 15pt; width: 130pt;" width="173" height="20">Phrase</td>   <td style="width: 140pt;" width="186">Assigned</td>  </tr>  <tr style="height: 15pt;" height="20">   <td style="height: 15pt;" height="20">the ocean is blue</td>   <td>blue</td>  </tr>  <tr style="height: 15pt;" height="20">   <td style="height: 15pt;" height="20">I like his blue shirt</td>   <td>blue</td>  </tr> </tbody></table>
And then using the value to lookup in the table:

=VLOOKUP(B2,$E$2:$F$5,2,FALSE)

And it's done! To enhance the search, just modify the pattern and voalá!!!

Thanks
Julio 
<table style="border-collapse: collapse; width: 48pt;" width="64" border="0" cellpadding="0" cellspacing="0"><col style="width: 48pt;" width="64"><tbody><tr style="height: 15pt;" height="20">   <td style="height: 15pt; width: 48pt;" width="64" height="20">
</td> </tr></tbody></table>


----------



## andrewman

*Re: June/July 2008 Challenge of the Month*



MrExcel said:


> I've posted a new *challenge of the month* today. Like the last challenge, this one will have many different approaches. Post your entries here. While the ultimate "best" entry wins the LiveLessons DVD, several podcast DVD's are available to anyone who proposes a significant advancement towards a cool solution.
> 
> Entries are due by 15 July 2008.
> 
> Bill Jelen


 
When we have the result for June/July 2008 Challenge?


----------



## Jonmo1

*Re: June/July 2008 Challenge of the Month*

Seriously, here we are in October. I'm actually curious, this is the first challenge I've participated in. When/How will we know who wins?  And when might there be a new challenge?


----------



## stanleydgromjr

*Re: June/July 2008 Challenge of the Month*

When/How will we know who wins? And when might there be a new challenge?


Have a great day,
Stan


----------



## gavinkelly

*Re: June/July 2008 Challenge of the Month*

I think a name change is in order, perhaps "Challenge once in a blue moon".

Come on pick a winner and make a new challenge please


----------



## Randombard

*Re: June/July 2008 Challenge of the Month*

I know that the primary driving aspect of this formula has already been posted,

I have just added to it to make it more versatile.

=IF(ISERROR(LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)),"Not In List",LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10))

In no way can I take credit for the clever part of this formula, I just noticed that on those occations that the word in A1 was not in the lookup vector I got #N/A


----------



## davejago

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)



Can someone help me to break this formula out in layman's terms for me? I'm an intermediate excel user, but I don't understand how this is working.


----------



## EugeneCarter

*Re: June/July 2008 Challenge of the Month*



davejago said:


> Can someone help me to break this formula out in layman's terms for me? I'm an intermediate excel user, but I don't understand how this is working.


 Check out the posts from around Jun 17th, 2008 and the links within them.  There were many posts on Barry's solution.


----------



## andrewman

*Re: June/July 2008 Challenge of the Month*

When we have the result for June/July 2008 Challenge?


----------



## mgirvin

*Re: June/July 2008 Challenge of the Month*

That is a good question! I have been waiting too!

In fact, in the MrExcel Survey they just sent out yesterday, I said that they should do more of this monthly challenge stuff!


----------



## Mattison

*Re: June/July 2008 Challenge of the Month*

A minor tweak I think could make the "fastest" formula faster...

By changing it from: =LOOKUP(9^6,SEARCH(D$2:D$10,A2),E$2:E$10)

to: =LOOKUP(LEN(A2),SEARCH(D$2:D$10,A2),E$2:E$10)

...it would only search only the number of characters actually in the cell, not the ~32k as previously defined.


----------



## bosco_yip

*Re: June/July 2008 Challenge of the Month*



Mattison said:


> A minor tweak I think could make the "fastest" formula faster...
> 
> By changing it from: =LOOKUP(9^6,SEARCH(D$2:D$10,A2),E$2:E$10)
> 
> to: =LOOKUP(LEN(A2),SEARCH(D$2:D$10,A2),E$2:E$10)
> 
> ...it would only search only the number of characters actually in the cell, not the ~32k as previously defined.



Hi Mattison,

 9^6 is a number, 

but,

LEN(A2) is a function

Replaced 9^6 with LEN(A2) would add one more function to the formula

…..the changes made the formula slower

Regards
Bosco


----------



## QuinDavis

*Re: June/July 2008 Challenge of the Month*

Compared to others, I feel like such a beginner...  

Function FLookup(FullString As String, KeywordList As Range) As String
Dim Key As String
For i = 1 To KeywordList.Rows.Count
Debug.Print i & " " & FullString & " " & KeywordList(i, 1) & " " & KeywordList(i, 2)
    Key = "*" & KeywordList(i, 1) & "*"
    If KeywordList(i, 1) = "" Then Exit Function
    If FullString Like Key Then
        For j = 1 To KeywordList.Rows.Count
            If KeywordList(i, 1) = KeywordList(j, 1) Then
                FLookup = KeywordList(j, 2)
                Exit Function
            End If
        Next
    End If
Next
End Function


----------



## tony567

*Re: June/July 2008 Challenge of the Month*



QuinDavis said:


> Compared to others, I feel like such a beginner...
> 
> Function FLookup(FullString As String, KeywordList As Range) As String
> Dim Key As String
> For i = 1 To KeywordList.Rows.Count
> Debug.Print i & " " & FullString & " " & KeywordList(i, 1) & " " & KeywordList(i, 2)
> Key = "*" & KeywordList(i, 1) & "*"
> If KeywordList(i, 1) = "" Then Exit Function
> If FullString Like Key Then
> For j = 1 To KeywordList.Rows.Count
> If KeywordList(i, 1) = KeywordList(j, 1) Then
> FLookup = KeywordList(j, 2)
> Exit Function
> End If
> Next
> End If
> Next
> End Function


 
QuinDavis<SCRIPT type=text/javascript> vbmenu_register("postmenu_1768518", true); </SCRIPT> 

Join Date: Dec 2008
Posts: 0 



QuinDavis <<<<< you got zero count on posting??? 
How you did that?


----------



## QuinDavis

*Re: June/July 2008 Challenge of the Month*



> QuinDavis <<<<< you got zero count on posting???
> How you did that?


 
I'm either a master hacker or a virgin newbee...    (Not hacker..)


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Posts in the Lounge do not count towards your total post count - so if QuinDavis has not posted in any other forum on the Board then he will have a post count of zero


----------



## tony567

*Re: June/July 2008 Challenge of the Month*



RichardSchollar said:


> Posts in the Lounge do not count towards your total post count - so if QuinDavis has not posted in any other forum on the Board then he will have a post count of zero


 

QuinDavis.. i know what you did....


----------



## crimson_b1ade

*Re: June/July 2008 Challenge of the Month*

Challenge of the...Month?!? Last challenge was June/July 2008, and the previous challenge before that was March/April 2007. At that rate..."Challenge of the Year" would be a more fitting description.


----------



## mgirvin

*Re: June/July 2008 Challenge of the Month*

I agree: change it to challenge of the year if it remains as is, or do us all a favor and change it back to challenge of the month!


----------



## Arvind1977

*Re: June/July 2008 Challenge of the Month*

hi the formula helped me alot but can any one explain me what is for 2^15 i can understand the command please help.


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*



Arvind1977 said:


> hi the formula helped me alot but can any one explain me what is for 2^15 i can understand the command please help.



Arvind

Search returns the starting position of the searched-for text within the cell.  Maximum cell text length is 32,767 which is 2^15-1.  Thus 2^15 represents a value which is at least 1 greater than the start position of any found text.  Frequently you will see 9.9999E+307 used in its place (especially when not dealing with cell length) just because this is a bigger number than almost anything you will ever see in Excel.  Lookup returns the last value which is less than or equal to the Lookup value - hence by choosing these numbers you are guaranteeing that the lookup value will be greater than the values returned by Search in the Lookup_range - so that if the searched-for term is found, Lookup will always returna result.


----------



## narendra

*Re: June/July 2008 Challenge of the Month*

How is it that Total No of Posts "Daniel Ferry" is shown as 0.
Is it that he has tweaked some settings or my PC has a Problem.

Or is it something else.

Check his Post# 66 & 67 (Pg 7) on this thread. Or his page in Members Profile Confirming the same.


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Posts to the Lounge do not count towards total post count - hence if a member has not posted before or has only posted into the Lounge then his/her postcount will show as zero.


----------



## Oorang

*Re: June/July 2008 Challenge of the Month*

Has a winner been announced yet?


----------



## Mr excel novice

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)


 
Genius , but 
-forgot one thing! 
the challenge was for additional list items to be added without alteration to the function - keep your original with:

=LOOKUP(2^15,SEARCH(Keyword,A2),Assign)
where the defined names are:
Keyword =OFFSET(Sheet1!$D$1,1,0,(COUNTA(Sheet1!$D:$D)-1))
&
Assign =OFFSET(Sheet1!$E$1,1,0,(COUNTA(Sheet1!$E:$E))-1))


----------



## Mr excel novice

*Re: June/July 2008 Challenge of the Month*



Mr excel novice said:


> Genius , but
> -forgot one thing!
> the challenge was for additional list items to be added without alteration to the function - keep your original with:
> 
> =LOOKUP(2^15,SEARCH(Keyword,A2),Assign)
> where the defined names are:
> Keyword =OFFSET(Sheet1!$D$1,1,0,(COUNTA(Sheet1!$D:$D)-1))
> &
> Assign =OFFSET(Sheet1!$E$1,1,0,(COUNTA(Sheet1!$E:$E))-1))


 
Sorry! 
just noticed that this was covered before.
You could also change the 2^15 to COUNTA(Phrases), with dynamic range but this won't make the function any different.


----------



## Richard Schollar

*Re: June/July 2008 Challenge of the Month*

Hi Everyone


It will come as no surprise to anyone that in 1st place was the _great_ Barry Houdini with his superlative Lookup formula.  

The full list of winners and honourable mentions can be found here (there are quite a few of them!):

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 12"><meta name="Originator" content="Microsoft Word 12"><link rel="File-List" href="file:///C:%5CUsers%5CRichard%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"><link rel="themeData" href="file:///C:%5CUsers%5CRichard%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"><link rel="colorSchemeMapping" href="file:///C:%5CUsers%5CRichard%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml"><!--[if gte mso 9]><xml>  <w:WordDocument>   <w:View>Normal</w:View>   <w:Zoom>0</w:Zoom>   <w:TrackMoves/>   <w:TrackFormatting/>   <w:PunctuationKerning/>   <w:ValidateAgainstSchemas/>   <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>   <w:IgnoreMixedContent>false</w:IgnoreMixedContent>   <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>   <w:DoNotPromoteQF/>   <w:LidThemeOther>EN-GB</w:LidThemeOther>   <w:LidThemeAsian>X-NONE</w:LidThemeAsian>   <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>   <w:Compatibility>    <w:BreakWrappedTables/>    <w:SnapToGridInCell/>    <w:WrapTextWithPunct/>    <w:UseAsianBreakRules/>    <w:DontGrowAutofit/>    <w:SplitPgBreakAndParaMark/>    <w:DontVertAlignCellWithSp/>    <w:DontBreakConstrainedForcedTables/>    <w:DontVertAlignInTxbx/>    <w:Word11KerningPairs/>    <w:CachedColBalance/>   </w:Compatibility>   <w:DoNotOptimizeForBrowser/>   <m:mathPr>    <m:mathFont m:val="Cambria Math"/>    <m:brkBin m:val="before"/>    <m:brkBinSub m:val="--"/>    <m:smallFrac m:val="off"/>    <m:dispDef/>    <m:lMargin m:val="0"/>    <m:rMargin m:val="0"/>    <m:defJc m:val="centerGroup"/>    <m:wrapIndent m:val="1440"/>    <m:intLim m:val="subSup"/>    <m:naryLim m:val="undOvr"/>   </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml>  <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"   DefSemiHidden="true" DefQFormat="false" DefPriority="99"   LatentStyleCount="267">   <w:LsdException Locked="false" Priority="0" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Normal"/>   <w:LsdException Locked="false" Priority="9" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>   <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>   <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>   <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>   <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>   <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>   <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>   <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>   <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>   <w:LsdException Locked="false" Priority="39" Name="toc 1"/>   <w:LsdException Locked="false" Priority="39" Name="toc 2"/>   <w:LsdException Locked="false" Priority="39" Name="toc 3"/>   <w:LsdException Locked="false" Priority="39" Name="toc 4"/>   <w:LsdException Locked="false" Priority="39" Name="toc 5"/>   <w:LsdException Locked="false" Priority="39" Name="toc 6"/>   <w:LsdException Locked="false" Priority="39" Name="toc 7"/>   <w:LsdException Locked="false" Priority="39" Name="toc 8"/>   <w:LsdException Locked="false" Priority="39" Name="toc 9"/>   <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>   <w:LsdException Locked="false" Priority="10" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Title"/>   <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>   <w:LsdException Locked="false" Priority="11" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>   <w:LsdException Locked="false" Priority="22" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Strong"/>   <w:LsdException Locked="false" Priority="20" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>   <w:LsdException Locked="false" Priority="59" SemiHidden="false"    UnhideWhenUsed="false" Name="Table Grid"/>   <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>   <w:LsdException Locked="false" Priority="1" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>   <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading"/>   <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List"/>   <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid"/>   <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1"/>   <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2"/>   <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1"/>   <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2"/>   <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1"/>   <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2"/>   <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3"/>   <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List"/>   <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading"/>   <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List"/>   <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid"/>   <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 1"/>   <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 1"/>   <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 1"/>   <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>   <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>   <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>   <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>   <w:LsdException Locked="false" Priority="34" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>   <w:LsdException Locked="false" Priority="29" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Quote"/>   <w:LsdException Locked="false" Priority="30" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>   <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>   <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>   <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>   <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>   <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 1"/>   <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>   <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 1"/>   <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>   <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 2"/>   <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 2"/>   <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 2"/>   <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>   <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>   <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>   <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>   <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>   <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>   <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>   <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 2"/>   <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>   <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 2"/>   <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>   <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 3"/>   <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 3"/>   <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 3"/>   <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>   <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>   <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>   <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>   <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>   <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>   <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>   <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 3"/>   <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>   <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 3"/>   <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>   <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 4"/>   <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 4"/>   <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 4"/>   <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>   <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>   <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>   <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>   <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>   <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>   <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>   <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 4"/>   <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>   <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 4"/>   <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>   <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 5"/>   <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 5"/>   <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 5"/>   <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>   <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>   <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>   <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>   <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>   <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>   <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>   <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 5"/>   <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>   <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 5"/>   <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>   <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 6"/>   <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 6"/>   <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 6"/>   <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>   <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>   <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>   <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>   <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>   <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>   <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>   <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 6"/>   <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>   <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 6"/>   <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>   <w:LsdException Locked="false" Priority="19" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>   <w:LsdException Locked="false" Priority="21" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>   <w:LsdException Locked="false" Priority="31" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>   <w:LsdException Locked="false" Priority="32" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>   <w:LsdException Locked="false" Priority="33" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>   <w:LsdException Locked="false" Priority="37" Name="Bibliography"/>   <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>  </w:LatentStyles> </xml><![endif]--><style> <!--  /* Font Definitions */  @font-face 	{font-family:"Cambria Math"; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-charset:1; 	mso-generic-font-family:roman; 	mso-font-formatther; 	mso-font-pitch:variable; 	mso-font-signature:0 0 0 0 0 0;} @font-face 	{font-family:Calibri; 	panose-1:2 15 5 2 2 2 4 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1073750139 0 0 159 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:""; 	margin:0cm; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi; 	mso-fareast-language:EN-US;} a:link, span.MsoHyperlink 	{mso-style-priority:99; 	color:blue; 	mso-themecolor:hyperlink; 	text-decoration:underline; 	text-underline:single;} a:visited, span.MsoHyperlinkFollowed 	{mso-style-noshow:yes; 	mso-style-priority:99; 	colorurple; 	mso-themecolor:followedhyperlink; 	text-decoration:underline; 	text-underline:single;} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi; 	mso-fareast-language:EN-US;} @page Section1 	{size:612.0pt 792.0pt; 	margin:72.0pt 72.0pt 72.0pt 72.0pt; 	mso-header-margin:36.0pt; 	mso-footer-margin:36.0pt; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --> </style><!--[if gte mso 10]> <style>  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-qformat:yes; 	mso-style-parent:""; 	mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 	mso-para-margin:0cm; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-theme-font:minor-fareast; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin;} </style> <![endif]-->[FONT=&quot]http://www.mrexcel.com/pc18.shtml[/FONT]

Well done to everyone who took part!

I have it on good authority that another Challenge will be posted shortly and this time the timescales will be somewhat tighter


----------



## Malix

Follwing is my solution towards previous chellange. I am new at forum and need inspitaion from all of you.

=TRIM(IF(ISNUMBER(FIND("blue",A2))=TRUE,"Joe","")&IF(ISNUMBER(FIND("red",A2))=TRUE,"Bob","")&IF(ISNUMBER(FIND("yellow",A2))=TRUE,"Mary","")&IF(ISNUMBER(FIND("pink",A2))=TRUE,"Fred","")&IF(ISNUMBER(FIND("orange",A2))=TRUE,"Ralph","")&IF(ISNUMBER(FIND("brown",A2))=TRUE,"Lora","")&IF(ISNUMBER(FIND("white",A2))=TRUE,"Tracy","")&IF(ISNUMBER(FIND("lavendar",A2))=TRUE,"Earl","")&IF(ISNUMBER(FIND("magenta",A2))=TRUE,"Jenny",""))

Regards
Arshad


----------



## barry houdini

*Re: June/July 2008 Challenge of the Month*



RichardSchollar said:


> ......Barry Houdini with his superlative Lookup formula.


 
OK, I'm officially flattered, thanks Bill...but I have to say that the solution is by no means original, I probably picked it up from somebody on this board, most likely Aladin.......

So thanks to Aladin and everybody who has contributed to my ongoing Excel education here, and everybody else who participated in the Challenge. I'm already looking forward to the next one......


----------



## Salvita

*Re: June/July 2008 Challenge of the Month*

Kudos, Barry!

I just found this site yesterday and so far, I have learned so much!

I had a tough time trying to understand Houdini's solution, but finally did it, mostly thanks to Rhino Dance's post #157.

There is still one issue that eludes me: control-shift-enter. What is this for?

I know I am late, but would like to offer this macro as the WORST offered here, but still, I wrote it, so here it is:

Public Sub SOLUTION()
Dim renPhrases As Integer
Dim renKey As Integer
Dim nKey As Integer
Dim nPhrases As Integer
Dim color As String
Dim Assigned As String
Dim phrase As String
renPhrases = Range("A65536").End(xlUp).Row
renKey = Range("D65536").End(xlUp).Row
For nKey = 2 To renKey
    color = Cells(nKey, 4)
    Assigned = Cells(nKey, 5)

    For nPhrases = 2 To renPhrases
        phrase = Cells(nPhrases, 1)
        If Cells(nPhrases, 2) = "" Then
            Cells(nPhrases, 2) = "=IF(ISERROR(FIND(" & """" & color & """" & "," & """" & phrase & """" & ")),"""",1)"
            If Cells(nPhrases, 2) = 1 Then
                Cells(nPhrases, 2) = Assigned
            Else: Cells(nPhrases, 2) = ""
            End If
        End If
    Next nPhrases
Next nKey
End Sub


----------



## Domski

*Re: June/July 2008 Challenge of the Month*



> There is still one issue that eludes me: control-shift-enter. What is this for?



It's for confirming a formula as what is known as a CSE or more commonly Array Formula. These work differently to other formula (other than maybe Sumproduct and some others in 2007) and as such Excel requires that you tell it as such that you are creating one.

There's a good intro to them here: http://www.cpearson.com/excel/ArrayFormulas.aspx

Dom


----------



## Hooseria

Hi, Just bought Book, by Jelen and Systad, discovered your Website (Wow!!) anyway I know this challenge is old. Don't understand why a VLookup doesn't work, heres a user adaptable version of my Lookup and an explanation of why I used each formula...... Would like to hear some comments about it.

Look forward to the next challenge.

={VLOOKUP((OFFSET($E$3,MATCH(TRUE,ISNUMBER(SEARCH(Keyword,B3)),0)-1,0)),Table,2,FALSE)}

1.) Enter new enteries within borders
2.) Copy Formula's down in column C to adjacent new entries in Column B
A.) Firstly I needed to extract the colours from the Phrases, then use vlookup to look it up in the adjacent table
B.) Two named ranges, 1 for extracting the colour, and second for the vlookup.

Keyword is the named range for the colours and and Table for the lookup table Column ("Keyword and Assigned to")

....How do you attach a file to a post??


----------



## Domski

Hi & welcome,



> ....How do you attach a file to a post??


 
You can't I'm afraid. Only way is to pop it on a hosting site and post the link.

Dom


----------



## Hooseria

Domski

Thanks, Could you reccomend a hosting site, I'm eager to get a response on my answer to the latest challenge. Will stick it in the Hosting site. Would be great for future threads as well.

Cheers


----------



## Domski

I don't use them myself but you could try www.box.net which I know a few folk use.


----------



## Hooseria

Domski

Thanks, Great site, Here's the attachment of my Answer to June Challenge Using a Vlookup of the Extracted Colour based on the Adjacent Table.
http://www.box.net/shared/rqcsgla6rf 
http://www.box.net/shared/rqcsgla6rf


----------



## Hooseria

Domski

My appologies, I've gathered that this link will not work, you'll get a PHP download, tell you what, forget it, I'm sure you've got other important stuff to do, this is not urgent or important.

Well thanks for the attention, Cheers.


----------



## Nilotna

I now, it's too long but I'm starting 
You can call this procedure from the WorkSheet_Activate and Worksheet_SelectionChange
*****************************
Public Sub Colorear()
Dim WB As Workbook
Dim Sh As Object
Dim RngColores As Range
Dim RngColor As Range
Dim RngFrases As Range
Dim RngCelda As Range
Dim rngAsignacion As Range
Dim DoFilaFrase As Double
Dim DoFilaColor As Double
Dim DoFinalRow As Double
Dim StPalabra As String
Dim StFrase As String
Dim InContador As Integer
Dim InCaracter As Integer
Dim InLongitud As Integer
Dim Asci As Integer
Set WB = ThisWorkbook
Set Sh = WB.Sheets("Sheet1")
'Determina el rango de Frases
DoFinalRow = Sh.Cells(Sh.Rows.Count, 1).End(xlUp).Row
Set RngFrases = Range(Sh.Cells(2, 1), Sh.Cells(DoFinalRow, 1))
Set rngAsignacion = Range(Sh.Cells(2, 2), Sh.Cells(DoFinalRow, 2))
rngAsignacion.Clear
'Determina el rango de Colores
DoFinalRow = Sh.Cells(Sh.Rows.Count, 4).End(xlUp).Row
Set RngColores = Sh.Range(Sh.Cells(2, 4), Sh.Cells(DoFinalRow, 4))
'Para cada frase
For Each RngCelda In RngFrases
    DoFilaFrase = RngCelda.Row  'Anota la fila de la frase
    StFrase = StreenCleaner(RngCelda.Value)
     'Busca un espacio
     InLongitud = Len(StFrase)
     For InContador = 1 To InLongitud + 1
        StCaracter = Mid(StFrase, InContador, 1)
            If StCaracter = " " Or InContador > InLongitud Then
            'Busca un nombre de color
            Set RngColor = RngColores.Find(What:=StPalabra, LookIn:=xlValues, lookat:= _
            xlWhole, searchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
            , SearchFormat:=False)
            If Not RngColor Is Nothing Then 'Es un color
                DoFilaColor = RngColor.Row 'Anota la fila del color
                'Escribe en la fila de la frase la segunda columna del color
                rngAsignacion(DoFilaFrase - 1, 1) = RngColores(DoFilaColor - 1, 2)
            Else
                StPalabra = ""
            End If 'No es un color
        Else
            StPalabra = StPalabra & StCaracter
        End If
      Next InContador
      StPalabra = ""
  Next RngCelda
End Sub

Public Function StreenCleaner(Cadena As String)
Dim Contador As Integer
Dim Caracter As String
Dim CadenaLimpia As String
Dim Prueba As Integer
For Contador = 1 To Len(Cadena)
    Caracter = Mid(Cadena, Contador, 1)
    On Error GoTo ErrXEsp
    If Asc(Caracter) > 128 Then Caracter = " "
        Prueba = Asc(Caracter)
    On Error GoTo 0
    CadenaLimpia = CadenaLimpia & Caracter
Next
    StreenCleaner = Trim(CadenaLimpia)
Exit Function
ErrXEsp:
    Caracter = " "
    Resume Next
End Function


----------



## basudip

Hello 

I see this site today. So its bit late (1 year i think)but I wrote a Macro to solve this. I dont know much about excel, Still learning. So can any body tell me is that my code is grown up or still childish

*******************
Sub test()
i = 1
Range("A2").Select
While ActiveCell.Value <> ""
a = ActiveCell.Value
b = Range("D2:E10").Value

If InStr(a, b(i, 1)) <> 0 Then
rw = ActiveCell.Row

Range("B" & rw).Value = b(i, 2)
i = 0
ActiveCell.Offset(1, 0).Select
End If
i = i + 1
Wend
End Sub

**********

Why Mr Excel not post anymore challange?? What happened to this site??


----------



## maheshmaxi

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)


 This is an excellent formula... Great Barry It helps me a lot...


----------



## strive4peace

Code:
__


Public Function VLookup_InAString( _
   pString As String _
   , pLookupTable As Range) As String

   ' written by Crystal
   ' strive4peace2009 at yahoo.com
   ' 6 July 09
   
   ' FIND a keyword in a string
   ' RETURN the value in the cell one column to the right
   
   'PARAMETERS
   ' pString is the value you are searching to find a keyword
   ' pLookupTable is the range of the Lookup Table
   '    assumptions
   '      1st column contains the keyword
   '      2nd column contains the value to return

   'EXAMPLE USEAGE
   ' cell formula --> =VLookup_InAString(A2, $D$2:$E$10)
    
   On Error GoTo Proc_Err
   
   Dim lngRow As Long _
      , arrValues() As String _
      , i As Integer
      
   ' replace no-break space with space
   pString = Replace(pString, Chr(160), " ")
   
   ' split passed string into an array using space as delimiter
   arrValues = Split(pString, " ")
      
   'test each word
   For i = LBound(arrValues) To UBound(arrValues)
   
      'compare the test word with each Keyword
      For lngRow = 0 To pLookupTable.Rows.Count - 1
      
         If Trim(UCase(arrValues(i))) = _
            Trim(UCase(pLookupTable.Offset(lngRow, 0).Resize(1, 1).Value)) Then
         
            'match was found -- return value in the second column of LookupTable
            VLookup_InAString = pLookupTable.Offset(lngRow, 1).Resize(1, 1).Value
            Exit Function
            
         End If
      Next lngRow

   Next i
   
   'comment this statement if you want the value to be blank
   VLookup_InAString = "NOT ASSIGNED"
 
Proc_Exit:
   Exit Function
  
Proc_Err:
   MsgBox Err.Description, , _
        "ERROR " & Err.Number _
        & "   VLookup_InAString"

   Resume Proc_Exit
   Resume
End Function


----------



## Qete_ARG

Barry Houdini...that was quick and impressive!
I didn´t read ALL the solutions, so I hope my UDF is not already posted by another user:


		Code:
__


Function AssignNameAccordingToColor(rngPhrase As Range, rngLookupTable As Range) As String
Dim i As Integer
Dim boolFound As Boolean
Dim FoundColor As String

boolFound = False

For i = 1 To rngLookupTable.Rows.Count
 If InStrRev(rngPhrase.Value, rngLookupTable.Cells(i, 1).Value) <> 0 Then
  FoundColor = rngLookupTable.Cells(i, 1).Value
  boolFound = True
  GoTo ColorFound
 End If
Next i
AssignNameAccordingToColor = "No matches"
Exit Function

ColorFound:
AssignNameAccordingToColor = Application.WorksheetFunction.VLookup(FoundColor, rngLookupTable, 2, 0)

End Function


----------



## mhalver

_Only just noticed after writing this up that this is an old challenge from last year (I noticed the deadline date but not the year when writing this), but wanted to post my solution anyways - maybe somebody will find it interesting, or somebody can learn something from it (possibly me from comments made on it).  This particular formula doesn't seem to have been posted, but some using the same concepts have._

Here is my solution:

Enter this formula into cell B2 as an array formula (Ctrl-Shift-Enter):

=IF(COUNTA(D:D)-1>1,OFFSET($D$2,MATCH(FALSE,ISERROR(FIND(OFFSET($D$2,0,0,COUNTA(D:D)-1,1),*A2*)),0)-1,1),IF(ISERROR(FIND($D$2,*A2*)),"",$E$2))​ 
The formula first looks to see how many entries are present in column D. If there is only 1, it uses the formula

=IF(ISERROR(FIND($D$2,*A2*)),"",$E$2)

If there are more than 1, it uses

=OFFSET($D$2,MATCH(FALSE,ISERROR(FIND(OFFSET($D$2,0,0,COUNTA(D:D)-1,1),*A2*)),0)-1,1)

The second formula checks each color and sees if it is *not* in the phrase, returning an array of trues and falses. It then finds the first false (the first color in the phrase), and finds the name corresponding to this. The first formula works the same way, but only with the single entry. If we know that there are multiple entries, we can just use the second formula (this one will fail if there is only a single entry).

The formula works, without modification, for any number of entries in the DE table (except 0) - I omitted the 0 case, as if we are attempting to solve this problem, we can assume that there must be some data. Some modification can be made if we must consider this case.


----------



## iluxo

I have this solutions:

=VLOOKUP(INDEX($D$2:$D$10,INDEX(MATCH(9999,SEARCH($D$2:$D$10,J4)),1)),$D$2:$E$10,2)

=VLOOKUP(INDEX($D$2:$D$10,MATCH(9999,SEARCH($D$2:$D$10,A2))),$D$2:$E$10,2)

number 9999 is only a "big" number, hoping the search list is not big enough, but it can be replaced with another really big.


----------



## iluxo

Ooops.. 
I forgot the false condition

=VLOOKUP(INDEX($D$2:$D$10,INDEX(MATCH(9999,SEARCH($D$2:$D$10,J4)),1)),$D$2:$E$10,2*,false*)

=VLOOKUP(INDEX($D$2:$D$10,MATCH(9999,SEARCH($D$2:$D$10,A2))),$D$2:$E$10,2*,false*)

thanks.


----------



## Phamacom80

Hi Everyone,

I'm new to this forum and would like to understand what exactly does this formula do in solving the monthly challenge.

=LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)

I understand what the Lookup function does and I understand what the Search function. The search function if entered alone will provide an error of #VALUE. Also, why are we are looking up 2 to 15th power. I'm absolutely confuse.

Thanks.


----------



## Richard Schollar

Hi Pharmacom

Check out this brief explanation:

http://www.mrexcel.com/forum/showpost.php?p=1599318&postcount=34


----------



## Phamacom80

Richard,

After reading the post, I seem to be more confuse. Could you please explain it in lament's term. Thanks.

Phamacom80


----------



## Fowmy

This solution for the challenge was submitted by 
*Barry Houdini *

 =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)

Explanation:

SEARCH received D$2:D$10 as the  _findtext_ argument. So It returned the results as an array like this {14;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!} 
since the keyword "Blue" in A2 was found in the 1st row of the *keyword* column, SEARCH returned 14 (the position of the keyword from A2). 

Then, the results returned by the SEARCH is used for the _Lookup_vector_ argument of the Lookup function.

A cell can contain characters up to 32767 which is same as 2^15.

LOOKUP trie to match 32767 in the _ lookup_vector_ which is the search results shown above, since it could not find it, it matched the largest value that is 14 (the 1st value) sitting in the 1st position. so the lookup returned what ever found in the same position in _Assigned to_ column which is _Joe_.

Formula Result:

=LOOKUP(*2^15*,{*14*;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!},{"*Joe*";"Bob";"Mary";"Fred";"Ralph";"Lora";"Tracy";"Earl";"Jenny"})


----------



## Phamacom80

Thank you thank you. That's exactly what I needed. I now fully understand the answer.


----------



## excelproz

=IF(NOT(ISERROR(FIND("blue",A3))),VLOOKUP("blue",D:E,2),"")  &
 IF(NOT(ISERROR(FIND("red",A3))),VLOOKUP("red",D:E,2),"")  &
 IF(NOT(ISERROR(FIND("yellow",A3))),VLOOKUP("yellow",D:E,2),"")  &
 IF(NOT(ISERROR(FIND("pink",A3))),VLOOKUP("pink",D:E,2),"")  &
 IF(NOT(ISERROR(FIND("orange",A3))),VLOOKUP("orange",D:E,2),"")  &
 IF(NOT(ISERROR(FIND("brown",A3))),VLOOKUP("brown",D:E,2),"")  &
 IF(NOT(ISERROR(FIND("white",A3))),VLOOKUP("white",D:E,2),"")  &
 IF(NOT(ISERROR(FIND("lavendar",A3))),VLOOKUP("lavendar",D:E,2),"")  &
 IF(NOT(ISERROR(FIND("magenta",A3))),VLOOKUP("magenta",D:E,2),"")
adapted to any size via dragging down or double-clicking the corner .. no nesting used so it should be legit solution


----------



## Oorang

True. But that is some rough calculation time.


----------



## alexhett

*Re: June/July 2008 Challenge of the Month*

2^15 = 32,768
32,768 is exactly 1/2 of the maximum number of rows in an Excel 97-03 spreadsheet (65,536).  
2^16 = 65,536
I'm not sure exactly why it's 1/2 the max rows rather than the full amount of max rows, but...

The most elegant solution is always the simplest solution, provided that it is sufficient.

And from a pragmatic viewpoint, there's no point in wasting processing power handling that super large 3.9999999E307 number when you can use a smaller, but still sufficient one.


----------



## excelproz

*Re: June/July 2008 Challenge of the Month*



alexhett said:


> 2^15 = 32,768
> 32,768 is exactly 1/2 of the maximum number of rows in an Excel 97-03 spreadsheet (65,536).
> 2^16 = 65,536
> I'm not sure exactly why it's 1/2 the max rows rather than the full amount of max rows, but...
> 
> The most elegant solution is always the simplest solution, provided that it is sufficient.
> 
> And from a pragmatic viewpoint, there's no point in wasting processing power handling that super large 3.9999999E307 number when you can use a smaller, but still sufficient one.


 
are you talking about my solution or the "chosen" solution?


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*



alexhett said:


> 2^15 = 32,768
> 32,768 is exactly 1/2 of the maximum number of rows in an Excel 97-03 spreadsheet (65,536).
> 2^16 = 65,536
> I'm not sure exactly why it's 1/2 the max rows rather than the full amount of max rows, but...
> 
> The most elegant solution is always the simplest solution, provided that it is sufficient.
> 
> And from a pragmatic viewpoint, there's no point in wasting processing power handling that super large 3.9999999E307 number when you can use a smaller, but still sufficient one.


 
Are you claiming that

2^16

is processed faster than

9.99999999999999E+307

which is mentioned in Help under Excel specifications and limits? If so, would you also explain why?


----------



## Owen Luo

Cause I just found this forum. And I am so interested in Excel and VBA.

Here is my solution as an UDF.



		Code:
__


Function proLookUp(refCell As Range, rangeSrc As Range, indexNum As Integer)

     Dim i As Integer
     
     For i = 1 To rangeSrc.Rows.Count
           
        If InStr(1, refCell.Value, rangeSrc(i, 1).Value, vbTextCompare) > 0 Then proLookUp = rangeSrc(i, indexNum): Exit For
        
    Next i
     
End Function


sample usage, input "=proLookUp(A2,$D$2:$F$10,2)" in cell B2


----------



## thebowrests

Use the following function to extract the word from the phrase then use the vlookup formula to get the corresponding name.

Public Function instring(phrase, keyword)
Dim c As Range
For Each c In Range(keyword.Address)
If InStr(1, phrase, c.Value, vbTextCompare) > 0 Then instring = c.Value
Next c
End Function

=VLOOKUP(instring(A2,$D$2:$D$10),$D$2:$E$10,2,FALSE)


----------



## Utsav

*Re: June/July 2008 Challenge of the Month*

Dear Berry,
can u plz expalin this formula.
expecially 2^15  this part.

Utsav


----------



## Oorang

I'm not Barry, but I will take a stab at explaining his brilliance (someone correct me if I mess anything up). This formula makes use of not one, but several obscure facets of Excel so it's easier to understand if you break it out into pieces and digest one piece at a time. 

First, let's talk about SEARCH. A lot of us are already familiar with SEARCH; the SEARCH function returns the character position where a search value (“find_text”) is found at. So if you enter: 
	
	
	
	
	
	




		Code:
__


=SEARCH("Bar","Foo Bar Baz Bar")

 SEARCH will return 5. This is because the first character of the _first instance_ of Bar occurs at the 5th character of "Foo Bar Baz Bar" (“within_text”). The third argument of SEARCH won’t matter to this discussion so I am going to ignore that for now. Pretty simple so far, right?

Ok so let’s dig a little deeper. What few people know is that _the first parameter of SEARCH can take multiple find_text values._ What!? It's true. If you pass the "find_text" an Array or a Range, SEARCH will check each entry against the "within_text" to see if any cell/element in the “find_text" Range/Array is found.  Pretty neat right? There is a catch though: The return value comes in an array. 

Allow me to illustrate. If you enter 
	
	
	
	
	
	




		Code:
__


=SEARCH({"Baz","Bar"},"Foo Bar Baz")

 you would get a result (in the form of an array) reading: {9,5}. This is because "Baz" was found at the 9th character while "Bar" was found at the 5th. 

So what can you do with that? Of course if you enter the formula in a cell, you will only see "9". This is because a cell may only have one value. If a value is an array, the cell will treat the first element of the array as it’s value. _However_, any formula capable of receiving an array as a parameter can work with the full array. 

For example: INDEX returns the _N_th element of an array. If you had an array: {6,3,9} 
	
	
	
	
	
	




		Code:
__


=INDEX({6,3,9},2)

 returns 3 (the 2nd element). 
	
	
	
	
	
	




		Code:
__


=INDEX(SEARCH({"Baz","Bar"},"Foo Bar Baz"),2)

 returns 5 as this is the second element of the array returned by SEARCH. 

Got all that? Eyes glazed over yet?

Good

Now that you know the pertinent details of SEARCH, let’s consider what we need to know about LOOKUP. 

The first thing to know about lookup (this is important) is that if LOOKUP can't find the lookup_value, _it uses “the largest value in the array that is less than or equal to lookup_value”_.  Read it again, I’ll wait. 

OK,so this means if you enter 
	
	
	
	
	
	




		Code:
__


=LOOKUP(4,{0,2,4,1})

the return value will be 4. 4 is an exact match for 4, so 4 is returned. If you were to enter 
	
	
	
	
	
	




		Code:
__


=LOOKUP(3,{0,2,4,1})

 the return value will be 2. 2 is the greatest number in the array smaller than 4. So the return value is 2. This specific principle will be why you see the magic 2^15. More on that later. 

Moving on. LOOKUP can take a third argument called “result_vector”. This argument is also an Array/Range. If the third argument of LOOKUP is used, rather than returning the “the largest value in the array that is less than or equal to lookup_value” LOOKUP returns the element of the "result_vector" having the same index as the element found in the "lookup_vector".  Did your mind just boggle? I’ll give an example:
	
	
	
	
	
	




		Code:
__


=LOOKUP(4,{0,2,4,1,5},{4,7,2,1,0})

returns 2.  4 is an exact match for 4, found at the 3rd element of the lookup_vector parameter. Because the lookup_value was found at the 3rd position of the look_vector, the _return[/] value is the 3rd position of the return_vector. In this case that value is 2.

If you were to look up 3 instead of 4 the found element would be 2 (because there is no 3) so the return value would be... 7.

Alrighty, now that you know how all the pieces work, let's put it all together. To refresh your memory, here is Barry's very elegant formula again: 
	
	
	
	
	
	




		Code:



=LOOKUP(2^15,SEARCH(D$2:D$10,A4),E$2:E$10)

For the purposes of this explanation I will assume you pasted this formula into cell B2 of the example file and copied down. 

Notice that SEARCH is looking for any/all of the colors in column D. You can also see that because each formula evaluates only one cell, SEARCH is looking for those colors in just the cell next to the formula. SEARCH will check the phrase for any color, and will return an array filled with the results. The results for B3 would look something like this: {14,#Value!,#Value!,#Value!,...}. Blue will be found at the 14th character, but every other color searched for will not be found (thus #Value!). This array will now be passed into LOOKUP as the “lookup_vector” argument. 

Now about that magic “2^15”: LOOKUP has the results of SEARCH to sift through, but what should we be looking up? Because the array is a result of the SEARCH function, we know that the array’s values will be limited to numbers or the #Value! Error. And we know we don’t care about the colors that aren’t found, so we are looking for a number. 

Well, that’s all well and good, but of course we have no way of knowing what that number will be! The color could be found anywhere in the phrase! And this is why it’s important to know that when LOOKUP can't make an Exact match it will return the next largest number. So if we feed it number that is guaranteed to be bigger than anything in the array, LOOKUP will ignore the #Value! Errors and find the biggest number in the array as the match. 

So how big a number do we need? SEARCH returns the character it found the find_text at. So it can’t return any number larger than the maximum length of a cell. The maximum length is 32,767 characters. You may recognize this number as 1 less than 2 to the 15th power (2^15=32,768). So if we sift through array returned by SEARCH for 32,768 SEARCH will return the biggest number in the array. This nicely filters out all of those #Value! entries the represent value not found. And ensures that the element returned defiantly represent a found value. (Barry’s a clever guy.) Now that we have a found element, LOOKUP will return the corresponding lookup vector which happens to be  E$2:E$10... And Viola! The formula is compete. 

What? What happens if you have multiple values in a phrase? Darn, I thought you would miss that. Because LOOKUP is returning the biggest number smaller than an impossibly large number the entry matched will always be the one with the largest number. Right? Right?! Well… No. The matching part is true, but there is a caveat. If you are using the vector implementation of LOOKUP (the one with 3 arguments) then there is one other thing you need to know. 

The vector version of LOOKUP assumes the values it gets are  pre-sorted in ascending order. LOOKUP then begins checking entries from the final element backwards until it encounters a value less than or equal to the lookup_value. Do you see what happens? Because all the values are going to be less than 32,768 LOOKUP will stop at the first non-error value it encounters. In other words it will always match the color listed last. No matter where in the find_text the color is found, if it is found, the color position in the array returned by SEARCH is pegged to the order of the range. Thus Red takes precedence over blue, yellow over red etc. So if you need to, you can raise a color's precedence changing the list's order.

So that's it. Barry’s elegant little one-liner took my about 3 pages to explain (and possibly only slightly coherently) thanks to the hour. But that's the explanation. The only thing I can think to add is that if you are using this formula in very many cells, I would hard-code 2^15 so Excel doesn’t have to do that same math over and over again.

Once again kudos to Barry for such an outstanding solution._


----------



## earthworm

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)



Barry please explain the concept of the above formula

i m lost   especially the 2^15 one


----------



## Andrew Fergus

*Re: June/July 2008 Challenge of the Month*

I recommend you have a read of the reply immediately above your question.


----------



## Jonmo1

*Re: June/July 2008 Challenge of the Month*



> LOOKUP then *begins checking entries from the final element backwards* until it encounters a value less than or equal to the lookup_value.


 
Oorang, I can't thank you enough.
That sentence answers a question that I have battled with for a long time.

I was always on the assumption that it reads from the first element to the last...It never crossed my mind that it reads the list backwards.
Yes, I know what you get when you assume.

With formulas like
=LOOKUP(9.99999999999999E+307,A:A)
or
=LOOKUP(REPT("Z",255),A:A)

I always wondered why it returns the last value in the list when the list is not sorted.
Since those formulas are so darn usefull, I just accepted it as fact that it works like that, but I never understood why.
Till now.

And now it makes perfect sense.

Thanks again..


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*



jonmo1 said:


> Oorang, I can't thank you enough.
> That sentence answers a question that I have battled with for a long time.
> 
> I was always on the assumption that it reads from the first element to the last...It never crossed my mind that it reads the list backwards.
> Yes, I know what you get when you assume.
> 
> With formulas like
> =LOOKUP(9.99999999999999E+307,A:A)
> or
> =LOOKUP(REPT("Z",255),A:A)
> 
> I always wondered why it returns the last value in the list when the list is not sorted.
> Since those formulas are so darn usefull, I just accepted it as fact that it works like that, but I never understood why.
> Till now.
> 
> And now it makes perfect sense.
> 
> Thanks again..


 
It's highly probable that LOOKUP (and VLOOKUP, HLOOKUP, MATCH with the match-type set to 1) does a *binary search*. Here a link that attempts to explain the mechanics:

http://www.mrexcel.com/forum/showthread.php?t=310278 (Post #7)

Situation III covers precisely the formulas in question.


----------



## earthworm

Oorang said:


> I'm not Barry, but I will take a stab at explaining his brilliance (someone correct me if I mess anything up). This formula makes use of not one, but several obscure facets of Excel so it's easier to understand if you break it out into pieces and digest one piece at a time.
> 
> First, let's talk about SEARCH. A lot of us are already familiar with SEARCH; the SEARCH function returns the character position where a search value (“find_text”) is found at. So if you enter:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Code:
> __
> 
> 
> =SEARCH("Bar","Foo Bar Baz Bar")
> 
> SEARCH will return 5. This is because the first character of the _first instance_ of Bar occurs at the 5th character of "Foo Bar Baz Bar" (“within_text”). The third argument of SEARCH won’t matter to this discussion so I am going to ignore that for now. Pretty simple so far, right?
> 
> Ok so let’s dig a little deeper. What few people know is that _the first parameter of SEARCH can take multiple find_text values._ What!? It's true. If you pass the "find_text" an Array or a Range, SEARCH will check each entry against the "within_text" to see if any cell/element in the “find_text" Range/Array is found.  Pretty neat right? There is a catch though: The return value comes in an array.
> 
> Allow me to illustrate. If you enter
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Code:
> __
> 
> 
> =SEARCH({"Baz","Bar"},"Foo Bar Baz")
> 
> you would get a result (in the form of an array) reading: {9,5}. This is because "Baz" was found at the 9th character while "Bar" was found at the 5th.
> 
> So what can you do with that? Of course if you enter the formula in a cell, you will only see "9". This is because a cell may only have one value. If a value is an array, the cell will treat the first element of the array as it’s value. _However_, any formula capable of receiving an array as a parameter can work with the full array.
> 
> For example: INDEX returns the _N_th element of an array. If you had an array: {6,3,9}
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Code:
> __
> 
> 
> =INDEX({6,3,9},2)
> 
> returns 3 (the 2nd element).
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Code:
> __
> 
> 
> =INDEX(SEARCH({"Baz","Bar"},"Foo Bar Baz"),2)
> 
> returns 5 as this is the second element of the array returned by SEARCH.
> 
> Got all that? Eyes glazed over yet?
> 
> Good
> 
> Now that you know the pertinent details of SEARCH, let’s consider what we need to know about LOOKUP.
> 
> The first thing to know about lookup (this is important) is that if LOOKUP can't find the lookup_value, _it uses “the largest value in the array that is less than or equal to lookup_value”_.  Read it again, I’ll wait.
> 
> OK,so this means if you enter
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Code:
> __
> 
> 
> =LOOKUP(4,{0,2,4,1})
> 
> the return value will be 4. 4 is an exact match for 4, so 4 is returned. If you were to enter
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Code:
> __
> 
> 
> =LOOKUP(3,{0,2,4,1})
> 
> the return value will be 2. 2 is the greatest number in the array smaller than 4. So the return value is 2. This specific principle will be why you see the magic 2^15. More on that later.
> 
> Moving on. LOOKUP can take a third argument called “result_vector”. This argument is also an Array/Range. If the third argument of LOOKUP is used, rather than returning the “the largest value in the array that is less than or equal to lookup_value” LOOKUP returns the element of the "result_vector" having the same index as the element found in the "lookup_vector".  Did your mind just boggle? I’ll give an example:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Code:
> __
> 
> 
> =LOOKUP(4,{0,2,4,1,5},{4,7,2,1,0})
> 
> returns 2.  4 is an exact match for 4, found at the 3rd element of the lookup_vector parameter. Because the lookup_value was found at the 3rd position of the look_vector, the _return[/] value is the 3rd position of the return_vector. In this case that value is 2.
> 
> If you were to look up 3 instead of 4 the found element would be 2 (because there is no 3) so the return value would be... 7.
> 
> Alrighty, now that you know how all the pieces work, let's put it all together. To refresh your memory, here is Barry's very elegant formula again:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Code:
> 
> 
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A4),E$2:E$10)
> 
> For the purposes of this explanation I will assume you pasted this formula into cell B2 of the example file and copied down.
> 
> Notice that SEARCH is looking for any/all of the colors in column D. You can also see that because each formula evaluates only one cell, SEARCH is looking for those colors in just the cell next to the formula. SEARCH will check the phrase for any color, and will return an array filled with the results. The results for B3 would look something like this: {14,#Value!,#Value!,#Value!,...}. Blue will be found at the 14th character, but every other color searched for will not be found (thus #Value!). This array will now be passed into LOOKUP as the “lookup_vector” argument.
> 
> Now about that magic “2^15”: LOOKUP has the results of SEARCH to sift through, but what should we be looking up? Because the array is a result of the SEARCH function, we know that the array’s values will be limited to numbers or the #Value! Error. And we know we don’t care about the colors that aren’t found, so we are looking for a number.
> 
> Well, that’s all well and good, but of course we have no way of knowing what that number will be! The color could be found anywhere in the phrase! And this is why it’s important to know that when LOOKUP can't make an Exact match it will return the next largest number. So if we feed it number that is guaranteed to be bigger than anything in the array, LOOKUP will ignore the #Value! Errors and find the biggest number in the array as the match.
> 
> So how big a number do we need? SEARCH returns the character it found the find_text at. So it can’t return any number larger than the maximum length of a cell. The maximum length is 32,767 characters. You may recognize this number as 1 less than 2 to the 15th power (2^15=32,768). So if we sift through array returned by SEARCH for 32,768 SEARCH will return the biggest number in the array. This nicely filters out all of those #Value! entries the represent value not found. And ensures that the element returned defiantly represent a found value. (Barry’s a clever guy.) Now that we have a found element, LOOKUP will return the corresponding lookup vector which happens to be  E$2:E$10... And Viola! The formula is compete.
> 
> What? What happens if you have multiple values in a phrase? Darn, I thought you would miss that. Because LOOKUP is returning the biggest number smaller than an impossibly large number the entry matched will always be the one with the largest number. Right? Right?! Well… No. The matching part is true, but there is a caveat. If you are using the vector implementation of LOOKUP (the one with 3 arguments) then there is one other thing you need to know.
> 
> The vector version of LOOKUP assumes the values it gets are  pre-sorted in ascending order. LOOKUP then begins checking entries from the final element backwards until it encounters a value less than or equal to the lookup_value. Do you see what happens? Because all the values are going to be less than 32,768 LOOKUP will stop at the first non-error value it encounters. In other words it will always match the color listed last. No matter where in the find_text the color is found, if it is found, the color position in the array returned by SEARCH is pegged to the order of the range. Thus Red takes precedence over blue, yellow over red etc. So if you need to, you can raise a color's precedence changing the list's order.
> 
> So that's it. Barry’s elegant little one-liner took my about 3 pages to explain (and possibly only slightly coherently) thanks to the hour. But that's the explanation. The only thing I can think to add is that if you are using this formula in very many cells, I would hard-code 2^15 so Excel doesn’t have to do that same math over and over again.
> 
> Once again kudos to Barry for such an outstanding solution._


_


I throughly read over and over again but still couldnt figure it out . 
i am familiar with the lookup function . but this 2^5  and 32,767 characters made me lost again . How did we found 32767 characters ? was there the formula for it ? secondly please explain in more simple manner of 2^5 thingy.
my brain just stop working on it   _


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*



earthworm said:


> Barry please explain the concept of the above formula
> 
> i m lost  especially the 2^15 one


 
The formula you are referring to:

=LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)

has the same structure as one often runs up against:

[1] LOOKUP(9.99999999999999E+307,MatchReference,ResultReference)

Reference stands for a vector like A2:A10 or an array like {1,#N/A,2,5,2}.

This expression returns the value from ResultReference that corresponds to the last numeric value in MatchReference. Note that:

[2] LOOKUP(9.99999999999999E+307,Reference)

always returns the last numeric value if one is available. How this works is explained in Post #7 at the following link:

http://www.mrexcel.com/forum/showthread.php?t=310278

Also, note that 9.99999999999999E+307 is a big constant mentioned in Excel's Help under "limits." So, 2^15 plays the same role, and in that sense, it's an unfortunate variation.

Back to [1]... The Search bit

SEARCH(D$2:D$10,A2)

yields an array reference of ten items, consisting of the #VALUE! errors and integer numbers. When a search value from D2:D10 is not in A2, we get a #VALUE! error, otherwise the start position of that search value in A2. When LOOKUP with the big number looks at this reference, it gets last position (integer) value and fetches the value that corresponds to it from E2:E10.


----------



## Jonmo1

^ is the power symbol
2 to the 15th power = 32768

Open up the calculator
press 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2
That results in 32768

That's how the Power works..


According to Excel Help Files, A cell can hold no more than 32767 characters.
Search returns the position # where the search value is found in the string.
If a string can only be 32767 characters long, then it is impossible for search to return a number larger than 32767.
so 32768 (2^15) is used to ensure the lookup value is larger than any possible result of the SEARCH function.

If the lookup value is larger than any value in the search range, then lookup returns the Next largest number value.
When the data is not sorted, that means it returns the last number value.


----------



## earthworm

*Re: June/July 2008 Challenge of the Month*



Aladin Akyurek said:


> The formula you are referring to:
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)
> 
> has the same structure as one often runs up against:
> 
> [1] LOOKUP(9.99999999999999E+307,MatchReference,ResultReference)
> 
> Reference stands for a vector like A2:A10 or an array like {1,#N/A,2,5,2}.
> 
> This expression returns the value from ResultReference that corresponds to the last numeric value in MatchReference. Note that:
> 
> [2] LOOKUP(9.99999999999999E+307,Reference)
> 
> always returns the last numeric value if one is available. How this works is explained in Post #7 at the following link:
> 
> http://www.mrexcel.com/forum/showthread.php?t=310278
> 
> Also, note that 9.99999999999999E+307 is a big constant mentioned in Excel's Help under "limits." So, 2^15 plays the same role, and in that sense, it's an unfortunate variation.
> 
> Back to [1]... The Search bit
> 
> SEARCH(D$2:D$10,A2)
> 
> yields an array reference of ten items, consisting of the #VALUE! errors and integer numbers. When a search value from D2:D10 is not in A2, we get a #VALUE! error, otherwise the start position of that search value in A2. When LOOKUP with the big number looks at this reference, it gets last position (integer) value and fetches the value that corresponds to it from E2:E10.



i m laughing at the moment as soon as i start reading in the middle of paragraph i m lost . please elaborate in very very simple terms . i m not that hardcoder vba guy . suppose you want to make a calculation in paper how would you do it . what i m facing problem is my basic understanding of this formula is not clear . i even read the link which you posted , couldnt get a clue.


----------



## mgirvin

Thanks Aladin!

I always use the metaphor of:

1) the lookup value starting at the beginning
2) looking at each value and asking "Am I bigger than you?"
3) when the answer is yes, it jumps back one row

But your color coded post of how it divides in two and checks is very helpful!!

They both will come to the same conclusion, but the "divide in two..." has to be faster!


----------



## Aladin Akyurek

mgirvin said:


> Thanks Aladin!
> 
> I always use the metaphor of:
> 
> 1) the lookup value starting at the beginning
> 2) looking at each value and asking "Am I bigger than you?"
> 3) when the answer is yes, it jumps back one row
> 
> But your color coded post of how it divides in two and checks is very helpful!!
> 
> They both will come to the same conclusion, but the "divide in two..." has to be faster!


 
Mike,

We have two algorithms regarding lookup functions: Linear search and binary search. VLOOKUP, HLOOKUP, and MATCH with the match-type set to 0 or FALSE does (a form of) linear search. With the match-type set to 1 or TRUE (or omitted) and LOOKUP by default does (a form of) binary search. That's why the latter are very fast: no cell by cell evaluation.

Regards,

Aladin


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*



earthworm said:


> i m laughing at the moment as soon as i start reading in the middle of paragraph i m lost . please elaborate in very very simple terms . i m not that hardcoder vba guy . suppose you want to make a calculation in paper how would you do it . what i m facing problem is my basic understanding of this formula is not clear . i even read the link which you posted , couldnt get a clue.


 
Consider:

<TABLE style="WIDTH: 364pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=485 x:str><COLGROUP><COL style="WIDTH: 163pt; mso-width-source: userset; mso-width-alt: 7936" width=217><COL style="WIDTH: 48pt" span=3 width=64><COL style="WIDTH: 57pt; mso-width-source: userset; mso-width-alt: 2779" width=76><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 163pt; HEIGHT: 12.75pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22 height=17 width=217> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 57pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22 width=76> </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22 height=17>Ontario meets GAD in a snowy day</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22 x:fmla="=LOOKUP(9.99999999999999E+307,SEARCH(D2:D3,A2),E2:E3)">Canada</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22>DAF</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22>America</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22 height=17> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22>GAD</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22>Canada</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22 height=17> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22>ZAD</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22>Kazakhstan</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22 height=17> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl22> </TD></TR></TBODY></TABLE>

A2: Ontario meets GAD in a snowy day

D2: DAF
D3: GAD
D4: ZAD

E2: America
E3: Canada
E4: Kazakhstan

B2:

=LOOKUP(9.99999999999999E+307,SEARCH(D2:D4,A2),E2:E4)

The SEARCH bit gives:

{#VALUE!;15;#VALUE!}

which means: D2 is not in A2, D3 is in A2, starting at the 15th char, and D4 is not in A2.

The last numeric value in {#VALUE!;15;#VALUE!} is 15, which is the 2nd item. LOOKUP then returns the 2nd item from E2:E4, which is Canada.

Does this help?


----------



## earthworm

jonmo1 said:


> ^ is the power symbol
> 2 to the 15th power = 32768
> 
> Open up the calculator
> press 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2
> That results in 32768
> 
> That's how the Power works..
> 
> 
> According to Excel Help Files, A cell can hold no more than 32767 characters.
> Search returns the position # where the search value is found in the string.
> If a string can only be 32767 characters long, then it is impossible for search to return a number larger than 32767.
> so 32768 (2^15) is used to ensure the lookup value is larger than any possible result of the SEARCH function.
> 
> If the lookup value is larger than any value in the search range, then lookup returns the Next largest number value.
> When the data is not sorted, that means it returns the last number value.



Now thats what i call user friendly explanation

1) A cell can hold no more than 32767 characters , now i understand the concept behind 2^5 , it means lookup value looks for value bigger then other value if first condition is not met so what he did was he set the highest limit for the search and obviously the data has to exist in such high limit

2) now what does this formula do is  ? as far as i have learned 
lookup value from the cell , then match the value from the table and then give the result from result column.

Now tell me how will excel read / calculate the above formula . you can explain in words only , i will catch it but please in simple words


----------



## Jonmo1

I can't imagine explaining it any better than Aladin did in his last post...

Except maybe add this



> =LOOKUP(9.99999999999999E+307,*SEARCH(D2:D4,A2)*,E2:E4)
> 
> The SEARCH bit gives:
> 
> *{#VALUE!;15;#VALUE!}*
> 
> So the formula can then be looked at like this, by just replacing the search function with it's resulting array of values.
> 
> =LOOKUP(9.99999999999999E+307,*{#VALUE!;15;#VALUE!}*,*E2:E4*)
> 
> Then replace *E2:E4* with it's values
> 
> =LOOKUP(9.99999999999999E+307,*{#VALUE!;15;#VALUE!}*,*{"America","Canada","Kazakhstan"}*)


 
So taking that, the lookup searches for the 9.9999 number in the FIRST array,
If exact match is not found (which we know it won't because of using the large number) then it matches the LAST Numeric Value from the right. So whatever position # the LAST numeric value is in the First array, the lookup returns the corresponding value from the Second array.
In this case, it's Canada


And to avoid the confusion...

Aladin used 9.99999999999999E+307 instead of 2^15 (or 32768).
Both numbers serve Exactly the same purpose, to be larger than any possible result of the Search Funciton.
It's just a personal choice of which one to use..


----------



## xymptlx

Great, but for someone who is trying to learn, it demonstrates that it works but not why....


----------



## Aladin Akyurek

xymptlx said:


> Great, but for someone who is trying to learn, it demonstrates that it works but not why....


 
Care to be specific? Is that LOOKUP with the big number?


----------



## earthworm

This is one of the best thread i have encountered soo far , the formula helped me alot and learned a lot from this .


----------



## Hooseria

I've posted this answer before, but couldn't post an example, I see you guys like Complicated long formulas and Macro's.

This simple array Vlookup formula works well on the challenge question.

Firstly The KeyWord List is A named Range "Keyword"  & the Keyword and Assigned to List is combined in a named range "Table". The length of both named ranges is the size of the phrase column. This makes it a continuos user friendly formula.
A               B                     C                  D                 E
Phrase       Formula                               Keyword         Assigned To

{=VLOOKUP((OFFSET($D$3,MATCH(TRUE,ISNUMBER(SEARCH(Keyword,A3)),0)-1,0)),Table,2,FALSE)}


----------



## earthworm

I Tried this formula but it dosent work correctly

on the below mention data

E1 = 54
E2 = 45
E3 = 65

What i want it if the Range has E1 i want the result of E1 Which is 54 but its not working what could be the problem please advice

=LOOKUP(2^5,SEARCH($C$5:$C$7,$H$5:$H$7),$D$5:$D$7)

The Underline formula is important because i dont want to select single cell


----------



## earthworm

bumppp...


----------



## barry houdini

Typically you wouldn't have a range as the second argument of SEARCH in this set up (i.e. where you have H5:H7). 

I don't understand your example in relation to that formula, you mention E1, E2 nad E3. Are they cell references, they don't appear in your formula?

Perhaps you can explain, with a small example, what you want to do. What data you have and in what cells and then what result you expect?


----------



## earthworm

barry houdini said:


> Typically you wouldn't have a range as the second argument of SEARCH in this set up (i.e. where you have H5:H7).
> 
> I don't understand your example in relation to that formula, you mention E1, E2 nad E3. Are they cell references, they don't appear in your formula?
> 
> Perhaps you can explain, with a small example, what you want to do. What data you have and in what cells and then what result you expect?


 

This an example

E1 = 9:00
E2 = 10:00
E3 = 15:00

The Above is the grid  based on this grid i have another colum where 

random data is entered like

CELL A1 =  M2
CELL A2 =  E2
CELL A3 =  E3
CELL A4 =  E1

from this colum i want the formula to look the values from random above data , match the value from grid and enter the value in sheet2

Cell A1 

I know i can also use vlookup but i want this formula to work.y is this showing same value check the attached sheet


----------



## trankim

THANK YOU THANK YOU THANK YOU for having this contest!  I had a similiar work related problem that needed Barry Houdini's Formula!

Worked LIKE a CHARM!


----------



## girishs

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)


 
Hi Barry
Will u please explain what is the use of 2^15 in this formula.


----------



## Oorang

lol Spoken like someone who didn't bother to read all 28 pages of the thread (Can't image why not.) It's been explained... Ad nauseum.


----------



## Ralph Gregory

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)


Very Good But it needs to expand to take in the larger array and be able to cope with no colours found in the string
try
=IF(ISERROR((LOOKUP(2^15,SEARCH((OFFSET(Sheet1!$D$2,0,0,COUNTA(Sheet1!$D$2:$D$40),1)),Sheet1!A2),Sheet1!$E$2:$E$40))),"",(LOOKUP(2^15,SEARCH((OFFSET(Sheet1!$D$2,0,0,COUNTA(Sheet1!$D$2:$D$40),1)),Sheet1!A2),Sheet1!$E$2:$E$40)))
thats ugly so I split it up into 3 named formlas like this
1st Name "Item" =OFFSET(Sheet1!$D$2,0,0,COUNTA(Sheet1!$D$2:$D$40),1)
2nd Name "DFind" =LOOKUP(2^15,SEARCH(Item),Sheet1!A2),Sheet1!$E$2:$E$40)
3rd Name "MyFind" =IF(ISERROR(DFind),"",DFind)
so my final Formula in the C Cells was 
=MyFind


I have modded it to do that bu it looks way too long


----------



## vassilg

It's been almost 2 years with no new Challenge of the Month...

Any thought on that mrexcel? 

Finding the most optimal solution is the biggest award!


----------



## Ralph Gregory

vassilg said:


> It's been almost 2 years with no new Challenge of the Month...
> 
> Any thought on that mrexcel?
> 
> Finding the most optimal solution is the biggest award!


yes I didnt notice the date of the challenge when I replied to the thread...bring us more challenges


----------



## trankim

Barry Houdini created this formula and I am hoping (he) or someone can help come up with a 2nd wild formula.  

Barry's original formula:
=Lookup(2^15,SEARCH($D$2:$D$10,A2),($E$2:$E$10)

Example: Let's say i have the opportunity identifier in Column A, the product line in Column B, i need it to match up against a table that has the returned value in Column C which is the # product/service, but ONLY if the column A and B matches up.

Barry's formula only looks for the Opportunity identifier column but can't match up against the other column headers for a match.  I need to copy the formula across all the cells.

Any help is appreciated!!!! 

Sheet 1 Cross Tab:
Column A is the opportunity Identifier
<TABLE style="WIDTH: 443pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=591 border=0><COLGROUP><COL style="WIDTH: 110pt; mso-width-source: userset; mso-width-alt: 5376; mso-outline-parent: collapsed" width=147><COL style="WIDTH: 71pt; mso-width-source: userset; mso-width-alt: 3474" width=95><COL style="WIDTH: 70pt; mso-width-source: userset; mso-width-alt: 3401" width=93><COL style="WIDTH: 48pt" span=4 width=64><TBODY><TR style="HEIGHT: 43.5pt; mso-height-source: userset" height=58><TD class=xl75 style="BORDER-RIGHT: black 0.5pt solid; BORDER-TOP: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; WIDTH: 110pt; BORDER-BOTTOM: black 0.5pt solid; HEIGHT: 43.5pt; BACKGROUND-COLOR: silver" width=147 height=58>Opportunity Identifier</TD><TD class=xl76 dir=ltr style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: white 0.5pt solid; BORDER-LEFT: white; WIDTH: 71pt; BORDER-BOTTOM: white 0.5pt solid; BACKGROUND-COLOR: #ff8080" width=95>Network Services</TD><TD class=xl76 dir=ltr style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: white 0.5pt solid; BORDER-LEFT: white; WIDTH: 70pt; BORDER-BOTTOM: white 0.5pt solid; BACKGROUND-COLOR: #ff8080" width=93>Storage Networking</TD><TD class=xl76 dir=ltr style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: white 0.5pt solid; BORDER-LEFT: white; WIDTH: 48pt; BORDER-BOTTOM: white 0.5pt solid; BACKGROUND-COLOR: #ff8080" width=64>Storage Supplies</TD><TD class=xl76 dir=ltr style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: white 0.5pt solid; BORDER-LEFT: white; WIDTH: 48pt; BORDER-BOTTOM: white 0.5pt solid; BACKGROUND-COLOR: #ff8080" width=64>STORAGE SUPPORT</TD><TD class=xl76 dir=ltr style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: white 0.5pt solid; BORDER-LEFT: white; WIDTH: 48pt; BORDER-BOTTOM: white 0.5pt solid; BACKGROUND-COLOR: #ff8080" width=64>PSG SUPPORT</TD><TD class=xl76 dir=ltr style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: white 0.5pt solid; BORDER-LEFT: white; WIDTH: 48pt; BORDER-BOTTOM: white 0.5pt solid; BACKGROUND-COLOR: #ff8080" width=64>Replacement Parts</TD></TR><TR style="HEIGHT: 42.75pt; mso-height-source: userset; mso-outline-parent: collapsed" height=57><TD class=xl69 style="BORDER-RIGHT: silver 0.5pt solid; BORDER-TOP: silver; BORDER-LEFT: silver 0.5pt solid; WIDTH: 110pt; BORDER-BOTTOM: silver 0.5pt solid; HEIGHT: 42.75pt; BACKGROUND-COLOR: transparent" align=left width=147 height=57>CRMEM1-2-197SPF3</TD><TD class=xl74 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right>=LOOKUP(2^15,SEARCH(Product!$A$2:$A$11894,$AE18),Product!$C$2:$C$65000)</TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD></TR><TR style="HEIGHT: 28.5pt; mso-height-source: userset" height=38><TD class=xl69 style="BORDER-RIGHT: silver 0.5pt solid; BORDER-TOP: silver; BORDER-LEFT: silver 0.5pt solid; WIDTH: 110pt; BORDER-BOTTOM: silver 0.5pt solid; HEIGHT: 28.5pt; BACKGROUND-COLOR: transparent" align=left width=147 height=38>CRMEM1-2-11KRLH7</TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD></TR><TR style="HEIGHT: 24pt; mso-height-source: userset" height=32><TD class=xl69 style="BORDER-RIGHT: silver 0.5pt solid; BORDER-TOP: silver; BORDER-LEFT: silver 0.5pt solid; WIDTH: 110pt; BORDER-BOTTOM: silver 0.5pt solid; HEIGHT: 24pt; BACKGROUND-COLOR: transparent" align=left width=147 height=32>CRMEM1-2-ZYNP3O</TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD><TD class=xl73 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"></TD></TR></TBODY></TABLE>


Sheet 2 Product is the Look Up Table:
<TABLE style="WIDTH: 328pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=436 border=0><COLGROUP><COL style="WIDTH: 93pt; mso-width-source: userset; mso-width-alt: 4534" width=124><COL style="WIDTH: 164pt; mso-width-source: userset; mso-width-alt: 7972" width=218><COL style="WIDTH: 71pt; mso-width-source: userset; mso-width-alt: 3437" width=94><TBODY><TR style="HEIGHT: 16.5pt" height=22><TD class=xl69 dir=ltr style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: white 0.5pt solid; BORDER-LEFT: white 0.5pt solid; WIDTH: 93pt; BORDER-BOTTOM: white 0.5pt solid; HEIGHT: 16.5pt; BACKGROUND-COLOR: #ff8080" width=124 height=22>Opportunity Identifier</TD><TD class=xl69 dir=ltr style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: white 0.5pt solid; BORDER-LEFT: white; WIDTH: 164pt; BORDER-BOTTOM: white 0.5pt solid; BACKGROUND-COLOR: #ff8080" width=218>Product Line Name</TD><TD class=xl69 dir=ltr style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: white 0.5pt solid; BORDER-LEFT: white; WIDTH: 71pt; BORDER-BOTTOM: white 0.5pt solid; BACKGROUND-COLOR: #ff8080" width=94># Product/Service</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl70 dir=ltr style="BORDER-RIGHT: #0066cc 0.5pt solid; BORDER-TOP: #0066cc 0.5pt solid; BORDER-LEFT: #0066cc 0.5pt solid; BORDER-BOTTOM: #0066cc 0.5pt solid; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" height=22>CRMAM1-3-11KEY65</TD><TD class=xl70 dir=ltr style="BORDER-RIGHT: #0066cc 0.5pt solid; BORDER-TOP: #0066cc 0.5pt solid; BORDER-LEFT: #0066cc; BORDER-BOTTOM: #0066cc 0.5pt solid; BACKGROUND-COLOR: transparent">Network Services</TD><TD class=xl71 dir=ltr style="BORDER-RIGHT: #0066cc 0.5pt solid; BORDER-TOP: #0066cc 0.5pt solid; BORDER-LEFT: #0066cc; BORDER-BOTTOM: #0066cc 0.5pt solid; BACKGROUND-COLOR: transparent">1</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl70 dir=ltr style="BORDER-RIGHT: #0066cc 0.5pt solid; BORDER-TOP: #0066cc; BORDER-LEFT: #0066cc 0.5pt solid; BORDER-BOTTOM: #0066cc 0.5pt solid; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" height=22>CRMAM1-3-13NHDDI</TD><TD class=xl70 dir=ltr style="BORDER-RIGHT: #0066cc 0.5pt solid; BORDER-TOP: #0066cc; BORDER-LEFT: #0066cc; BORDER-BOTTOM: #0066cc 0.5pt solid; BACKGROUND-COLOR: transparent">STORAGE SUPPORT</TD><TD class=xl71 dir=ltr style="BORDER-RIGHT: #0066cc 0.5pt solid; BORDER-TOP: #0066cc; BORDER-LEFT: #0066cc; BORDER-BOTTOM: #0066cc 0.5pt solid; BACKGROUND-COLOR: transparent">1</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl70 dir=ltr style="BORDER-RIGHT: #0066cc 0.5pt solid; BORDER-TOP: #0066cc; BORDER-LEFT: #0066cc 0.5pt solid; BORDER-BOTTOM: #0066cc 0.5pt solid; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" height=22>CRMAM1-3-13NHDDI</TD><TD class=xl70 dir=ltr style="BORDER-RIGHT: #0066cc 0.5pt solid; BORDER-TOP: #0066cc; BORDER-LEFT: #0066cc; BORDER-BOTTOM: #0066cc 0.5pt solid; BACKGROUND-COLOR: transparent">EVA Disk & SW</TD><TD class=xl71 dir=ltr style="BORDER-RIGHT: #0066cc 0.5pt solid; BORDER-TOP: #0066cc; BORDER-LEFT: #0066cc; BORDER-BOTTOM: #0066cc 0.5pt solid; BACKGROUND-COLOR: transparent">1</TD></TR></TBODY></TABLE>


----------



## trankim

Hi everyone,
It's me again.  The above problem was solved by Aladin and I truly thank him for his help.  However, I have another problem and it relates to the original function that Barry Houdini wrote.

I used his Lookup formula and it works BEAUTIFULLY; however, there is a quirk somewhere that I am not sure if it's me or the formula.

=LOOKUP(2^15,SEARCH(Category!$A$2:$A$167,J4),Category!$B$2:$B$167)

The above formula looks up the words in my category and applies it correctly.  However, some key words that it's supposed to look for doesn't get applied but instead another category is chosen.

The below description SHOULD return "Mission Critical" however, it returns "Attach" and there's no words or characters that I can see is related to "Attach" at all.  What's also strange is in most of my query, the "mission critical" returns the correct value...it's just some descriptions that do not.

Any help is GREATLY appreciated and I thank you in advance if you can help solve this problem.

here's the Look up in Column J4
1st example: AM TS Mission Critical Healthcare Express; US Q409-Q110
2nd example: GLobal TS MCS Healthcare Exp; AM CA Q409 Mail SRE and Telemarketing

Key word is A2:A167
Cateogry is B2:B167

<TABLE style="WIDTH: 174pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=232 border=0><COLGROUP><COL style="WIDTH: 126pt; mso-width-source: userset; mso-width-alt: 6144" width=168><COL style="WIDTH: 48pt" width=64><TBODY><TR style="HEIGHT: 16.5pt" height=22><TD class=xl204 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 126pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: yellow" align=left width=168 height=22>Key Word</TD><TD class=xl204 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 48pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: yellow" align=left width=64>Category</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>MC</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Mission Critical</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Maximize</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Maximise</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Investment</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Sustain</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Simulation</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Discovery</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Blade</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>MCS Healthcare</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Improving</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Proactive</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Select</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>P24</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>MCS</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Attach</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Weather</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Weathering</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Economic Storm</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>ECO</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>ECOStorm</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>CarePack</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Care</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Pack</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Just for You</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Unexpected Risks</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Protect</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Extend</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Storage Warranty</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Do it Right</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>ConvCarePack</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>TSPack</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 16.5pt; BACKGROUND-COLOR: transparent" align=left height=22>Post</TD><TD class=xl206 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>Attach</TD></TR></TBODY></TABLE>


----------



## Aladin Akyurek

I believe it would have been more appropriate to post this at Excel Questions... That said, try:

Define *Lrow* by means of Insert|Name|Define as referring to:

=MATCH(REPT("z",255),Category!$A:$A)

Define KEYWORDS as referring to:

=Category!$A$2:INDEX(Category!$A:$A,Lrow)

Define CATEGORIES as referring to:

=Category!$B$2:INDEX(Category!$B:$B,Lrow)

Now you can invoke:

=LOOKUP(9.99999999999999E+307,SEARCH(KEYWORDS,J4),CATEGORIES)




trankim said:


> Hi everyone,
> It's me again. The above problem was solved by Aladin and I truly thank him for his help. However, I have another problem and it relates to the original function that Barry Houdini wrote.
> 
> I used his Lookup formula and it works BEAUTIFULLY; however, there is a quirk somewhere that I am not sure if it's me or the formula.
> 
> =LOOKUP(2^15,SEARCH(Category!$A$2:$A$167,J4),Category!$B$2:$B$167)
> 
> The above formula looks up the words in my category and applies it correctly. However, some key words that it's supposed to look for doesn't get applied but instead another category is chosen.
> 
> The below description SHOULD return "Mission Critical" however, it returns "Attach" and there's no words or characters that I can see is related to "Attach" at all. What's also strange is in most of my query, the "mission critical" returns the correct value...it's just some descriptions that do not.
> 
> Any help is GREATLY appreciated and I thank you in advance if you can help solve this problem.
> 
> here's the Look up in Column J4
> 1st example: AM TS Mission Critical Healthcare Express; US Q409-Q110
> 2nd example: GLobal TS MCS Healthcare Exp; AM CA Q409 Mail SRE and Telemarketing
> 
> Key word is A2:A167
> Cateogry is B2:B167
> 
> <TABLE style="WIDTH: 174pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=232><COLGROUP><COL style="WIDTH: 126pt; mso-width-source: userset; mso-width-alt: 6144" width=168><COL style="WIDTH: 48pt" width=64><TBODY><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: yellow; WIDTH: 126pt; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl204 height=22 width=168 align=left>Key Word</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: yellow; WIDTH: 48pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl204 width=64 align=left>Category</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>MC</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Mission Critical</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Maximize</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Maximise</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Investment</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Sustain</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Simulation</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Discovery</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Blade</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>MCS Healthcare</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Improving</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Proactive</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Select</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>P24</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>MCS</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Mission Critical</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Attach</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Weather</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Weathering</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Economic Storm</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>ECO</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>ECOStorm</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>CarePack</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Care</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Pack</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Just for You</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Unexpected Risks</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Protect</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Extend</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Storage Warranty</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Do it Right</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>ConvCarePack</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>TSPack</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR><TR style="HEIGHT: 16.5pt" height=22><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 16.5pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 height=22 align=left>Post</TD><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl206 align=left>Attach</TD></TR></TBODY></TABLE>


----------



## trankim

Thank you Aladin for your response.  I truly apologize for posting it here.  You are absolutely right that I should have posted it in the Questions section, but my original intent was that I thought it was an easier trail to follow since my problem was similiar to the challenge.  I will take my request and post it to the correct forum as you suggested.

That said, the formula you gave worked the same way as the one I used from Barry Houdini.  It still returned the "Attach" vs "Mission Critical", but hopefully you can respond to any other suggestions when I post it in the correct forum.

New subject title will be "Fuzzy Match using Index or Search"


----------



## Aladin Akyurek

trankim said:


> Thank you Aladin for your response. I truly apologize for posting it here. You are absolutely right that I should have posted it in the Questions section, but my original intent was that I thought it was an easier trail to follow since my problem was similiar to the challenge. I will take my request and post it to the correct forum as you suggested.
> 
> That said, the formula you gave worked the same way as the one I used from Barry Houdini. It still returned the "Attach" vs "Mission Critical", but hopefully you can respond to any other suggestions when I post it in the correct forum.
> 
> New subject title will be "Fuzzy Match using Index or Search"


 
Trankim,

Have a closer look at KEYWORDS: You'll see that the formula succeeds also to find the string *care* in J4 and in the other example, whose associated CATEGORY is 'Attach'.

I propose the following modification...

=LOOKUP(9.99999999999999E+307,SEARCH(" "&KEYWORDS&" "," "&J4&" "),CATEGORIES)


----------



## kokomix

*Re: June/July 2008 Challenge of the Month*

Copied from Excel Help


		Code:
__


Sub FindColor()
    FinalRowD = Cells(1, 4).End(xlDown).Row
    For i = 2 To FinalRowD
        With Worksheets(1).Range("RngPhrases")
            Set c = .Find(Cells(i, 4).Value, LookIn:=xlValues)
            If Not c Is Nothing Then
                firstAddress = c.Address
                Do
                    c.Offset(, 1).Value = Cells(i, 5).Value
                    Set c = .FindNext(c)
                Loop While Not c Is Nothing And c.Address <> firstAddress
            End If
        End With
    Next i
End Sub

"RngPhrases" is dynamically defined as "=OFFSET(Sheet1!$A$2,0,0,COUNTA(Sheet1!$A:$A)-1,1)" in the Name Manager


----------



## vassilg

Guys and Gals,

This message does not belong here, and I wasn't sure where exactly it belongs, but for all of you XL-challengees out there, here's a new one:

Dare make the following chart with a Y-axis gap:






http://twitpic.com/1jbm96

[Creative XL Charts]

PS: I am still on 2003, maybe 2007 has more efficient chart func's


----------



## I L Brainerd

Here's my UDF macro for the challange it will locate the color in the line and find the correct person and display it in the cell. This will work with a large table. 


		Code:
__


Function MYTEST(MYSTRINGBLI) 'GET THE NAME ASSOCIATED WITH THE COLOR
MYTEST = Application.WorksheetFunction _
        .Index(Worksheets(1).Range("D2:E100"), Application.WorksheetFunction.Match(MYSTRINGBLI, Worksheets(1).Range("D2:D100"), True), 2)
End Function
Function MYTEST2(MYSTRINGILB) 'SHOW THE COLOR SO I CAN COMPARE IT
MYTEST2 = Application.WorksheetFunction _
        .Index(Worksheets(1).Range("D2:E100"), Application.WorksheetFunction.Match(MYSTRINGILB, Worksheets(1).Range("D2:D100"), 1), 1)
End Function
Function MYRESULT(MYSTRING) ' 5-24-10 WORKS TO FIND NAME ASSOCIATE TO COLOR IN LINE OF TEXT.
HOLDSTRING = MYSTRING
Dim MYHOLDSTRING As String
CNT = 1
WLEN = 0
HMB = 1
DONE = 1
HOLDNUM = 0
Do Until DONE = 0
    HOLDCHR = Mid(HOLDSTRING, CNT, 1)
    If ((HOLDCHR < Chr(65) Or HOLDCHR > Chr(122)) Or (HOLDCHR > Chr(90) And HOLDCHR < Chr(97))) Then
        If HMB > 1 Then
            WLEN = HMB
        End If
        MYRESULT = "NOT ASSIGNED"
        If MYTEST2(Mid(HOLDSTRING, CNT - WLEN, WLEN)) = Mid(HOLDSTRING, CNT - WLEN, WLEN) Then
            MYRESULT = MYTEST(Mid(HOLDSTRING, CNT - WLEN, WLEN))
            DONE = 0
        Else
            WLEN = 0
            MYRESULT = "NOT AVAILABLE"
        End If
    Else
        WLEN = WLEN + 1 'INCREMENT WORD LENGTH
        HMB = 0
    End If
If CNT > Len(HOLDSTRING) Then
    DONE = 0
End If
CNT = CNT + 1
HMB = HMB + 1
Loop
End Function

Enter into cell B2 the formula as follows 
=MYRESULT(A2)

The macro function will find the color and match it no matter were it is in the line.


----------



## rkee

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)



That is genius but I don't understand how it works... can someone explain to my simple brain what this does?


----------



## kriss

are there any moer monthly challenges?


----------



## _Zark

*Re: June/July 2008 Challenge of the Month*

[edit]: attempted delete.


----------



## mborg

*Re: June/July 2008 Challenge of the Month*

Barry, 
Can you explain what the "2^15" does in the lookup?  I am trying to wrap my head around this, but can't do it... thanks!


----------



## sous2817

Hello mborg,

Have a look at post #34 of the thread (http://www.mrexcel.com/forum/showpost.php?p=1599318&postcount=34)


----------



## paulsoliman

=LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)
...this is simply brilliant!!!


my first match solution (i know, too complex)...

{=INDEX($E$2:$E$10,MAX(IF($D$2:$D$10=MID(A2,MIN(IF(ISERROR(SEARCH($D$2:$D$10,A2)),LEN(A2),SEARCH($D$2:$D$10,A2))),LEN($D$2:$D$10)),ROW(INDIRECT("1:"&COUNTA($D$2:$D$10))),0)))}


----------



## Stefyu89

*Re: June/July 2008 Challenge of the Month*

i've got one which is less lenghty : =RECHERCHE(2;CHERCHE("*"&$B$7:$B$9;A13);$C$7:$C$9) ( recherche : french for lookup and cherche : french for search). 
The array after evaluation,  always gives me a 1 for any item found rather than the position of the lookup value in the cell as for Barry Houdini formula. 

Hope to have found something valuable.


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*



Stefyu89 said:


> i've got one which is less lenghty : =RECHERCHE(2;CHERCHE("*"&$B$7:$B$9;A13);$C$7:$C$9) ( recherche : french for lookup and cherche : french for search).
> The array after evaluation, always gives me a 1 for any item found rather than the position of the lookup value in the cell as for Barry Houdini formula.
> 
> Hope to have found something valuable.



Try rather:

=RECHERCHE(9,99999999999999E+307;CHERCHE("*"&$B$7:$B$9;A13);$C$7:$C$9)

See for a good reason:
http://www.mrexcel.com/forum/excel-questions/102091-9-9999999-a.html
http://www.mrexcel.com/forum/excel-...tiple-matches-match-returned.html#post1523998


----------



## Rick Rothstein

*Re: June/July 2008 Challenge of the Month*



Aladin Akyurek said:


> See for a good reason:
> http://www.mrexcel.com/forum/excel-questions/102091-9-9999999-a.html


I just added this post at the above referenced link...

Maybe in place of using 9.99999999999999E+307 for our largest number in LOOKUP's, we could use this 7-character shorter number instead... 10*1E+307


----------



## Stefyu89

@ Aladin

Thanks a lot Aladin for pointing me to some useful references. Meanwhile, i was already aware of this "Big Value" lookup method through you, actually through Mike Excelisfun Girvin who refers to you as the reference in formulas. A privilege to learn from you. Actually, i really wanted to emphasize the result from Search function which , like Barry Houdini case, gives the first position of the lookup text and when added an "*" indicates "1" for an item and "#VALUE" error for not found item. 

It's much more similar to  and less accurate than Ron Coderre formula on the same subject in another topic where "COUNTIF" is used to evaluate cell and "SUMPRODUCT" for adding all found items. 

Hope to be clear. Once more time for your dedication to Excel Community. You're a model for us.


----------



## Aladin Akyurek

Stefyu89 said:


> @ Aladin
> 
> Thanks a lot Aladin for pointing me to some useful references. Meanwhile, i was already aware of this "Big Value" lookup method through you, actually through Mike Excelisfun Girvin who refers to you as the reference in formulas. A privilege to learn from you. Actually, i really wanted to emphasize the result from Search function which , like Barry Houdini case, gives the first position of the lookup text and when added an "*" indicates "1" for an item and "#VALUE" error for not found item.
> 
> It's much more similar to and less accurate than Ron Coderre formula on the same subject in another topic where "COUNTIF" is used to evaluate cell and "SUMPRODUCT" for adding all found items.
> 
> Hope to be clear. Once more time for your dedication to Excel Community. You're a model for us.



Ma parole! Pas de problem. I know what you mean. And thanks for the kind words. To recap a small history:

1) Look up functions ignore error values if they possibly can (they can't if they are just fed with, e.g., {#VALUE!;#VALUE!}).

2) Look up functions with match type set to 1 (or TRUE) are really fast.

3) When a look up function is given a numerical look up value for looking it up in a numeric reference, with _BigNum_ sufficiently large

LOOKUP(BigNum,Reference)

returns invariably the last numeric value of Reference and does so very fast.

MATCH(BigNum,Reference,1)

returns the position of the last numeric value of Reference and does so very fast.

4) Sufficiently large means:

LOOKUP(*MAX(Reference)+Delta*,Reference)

where Delta is very small number (or just 1 for convenience's sake).

5) The reason for not using *MAX(Reference)+Delta* is threefold: 

it means an additional function call;
as function MAX is slow because it examines every cell in Reference;
MAX is sensitive to the presence of error values in Reference;

6) I've met the last value usage for the first time in a post by Dave Hawley and it's me (I believe) who introduced and showed with many others the usage worldwide thru forums (mrexcel, newsgroups, and so on).

7) I had something like 1E+30 as BigNum initially. After the following exchange with Mark W. in 2001...

Excel last number in column

I opted ever since for Excel's 9.99999999999999E+307.

8) Since there is no reason for choosing an ever-changing value for BigNum, 
I still use 9.99999999999999E+307 anchored in Excel itself (or a Pi-like contraction: 9.99E+307).

9) It would be really great if MS would provide names for such constants it is bounded with.


----------



## Marcelo Branco

Aladin,

Excellent explanation!

M.


----------



## Aladin Akyurek

Marcelo Branco said:


> Aladin,
> 
> Excellent explanation!
> 
> M.



Thanks Marcelo. Much appreciated.


----------



## pmp33

*Re: June/July 2008 Challenge of the Month*



barry houdini said:


> Here's one possibility.....
> 
> =LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10)



Hi barry, how would you modify this formula to match multiple columns keyword please, as per below:


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*

@pmp33
Care to post the sample in an Excel readable form? Images requires retying!


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*



pmp33 said:


> Hi barry, how would you modify this formula to match multiple columns keyword please, as per below:



Define *BigNum* using Formulas | Name Manager as referring to:


		Rich (BB code):
__


*=9.99999999999999E+307
*


C2, control+shift+enter, not just enter, and copy down:


		Rich (BB code):
__


*=LOOKUP(BigNum,
   SEARCH(IF($E$2:$E$12=$B2," "&$F$2:$F$12&" ",-BigNum)," "&$A2&" "),
   IF($E$2:$E$12=$B$2,$J$2:$J$12))
*


----------



## pmp33

*Re: June/July 2008 Challenge of the Month*



Aladin Akyurek said:


> Define *BigNum* using Formulas | Name Manager as referring to:
> 
> 
> Rich (BB code):
> __
> 
> 
> *=9.99999999999999E+307
> *
> 
> 
> C2, control+shift+enter, not just enter, and copy down:
> 
> 
> Rich (BB code):
> __
> 
> 
> *=LOOKUP(BigNum,
> SEARCH(IF($E$2:$E$12=$B2," "&$F$2:$F$12&" ",-BigNum)," "&$A2&" "),
> IF($E$2:$E$12=$B$2,$J$2:$J$12))
> *



I am so so grateful for that!!! This is so great! Thanks so much Aladin, I was working on this for 2 days already!
Much appreciated!! I should have come to mrexcel.com earlier!


----------



## pmp33

*Re: June/July 2008 Challenge of the Month*

As a thank you present I can provide you a link to a beautiful music I discovered this morning, hope you'll like it:
https://www.facebook.com/video.php?v=736503683056882


----------



## Aladin Akyurek

*Re: June/July 2008 Challenge of the Month*



pmp33 said:


> I am so so grateful for that!!! This is so great! Thanks so much Aladin, I was working on this for 2 days already!
> Much appreciated!! I should have come to mrexcel.com earlier!



You are welcome.



pmp33 said:


> As a thank you present I can provide you a link to a beautiful music I discovered this morning, hope you'll like it:
> https://www.facebook.com/video.php?v=736503683056882



Thanks!


----------

