![]() |
![]() |
|
|||||||
| Lounge v.2.0 A place to chat. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
.
Join Date: Feb 2002
Location: Akron, Ohio USA
Posts: 729
|
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
__________________
Preview my latest book for Free Last edited by RichardSchollar; Mar 13th, 2009 at 11:33 PM. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Moderator Contortionist Join Date: Apr 2005
Location: Hampshire, UK (Home); London, UK (Work)
Posts: 18,308
|
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 Microsoft MVP - Excel Need to post some data? PM me with your email address for the Beta version of the Board html maker! Last edited by RichardSchollar; Jun 17th, 2008 at 02:20 PM. |
|
|
|
|
|
#3 |
|
MrExcel MVP
Moderator Contortionist Join Date: Apr 2005
Location: Hampshire, UK (Home); London, UK (Work)
Posts: 18,308
|
In case of multiple occurrences of individual colours (could include submatches too eg red and redditch) 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
__________________
Richard Schollar Microsoft MVP - Excel Need to post some data? PM me with your email address for the Beta version of the Board html maker! |
|
|
|
|
|
#4 |
|
Join Date: Mar 2005
Posts: 2,055
|
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)
__________________
|
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Mar 2005
Location: England
Posts: 13,901
|
Here's one possibility.....
=LOOKUP(2^15,SEARCH(D$2:D$10,A2),E$2:E$10) |
|
|
|
|
|
#6 |
|
MrExcel MVP
Moderator Contortionist Join Date: Apr 2005
Location: Hampshire, UK (Home); London, UK (Work)
Posts: 18,308
|
That's great Barry!
__________________
Richard Schollar Microsoft MVP - Excel Need to post some data? PM me with your email address for the Beta version of the Board html maker! |
|
|
|
|
|
#7 |
|
Join Date: Mar 2005
Location: West Sussex, England
Posts: 440
|
taken a few minutes to get my head round it, but that is quality.
__________________
Its all about whats in your toolbox. I'll lend you my hammer. One day I might call to borrow your screwdriver. |
|
|
|
|
|
#8 |
|
Join Date: Apr 2007
Location: Cincinnati, Ohio
Posts: 5,337
|
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
__________________
Always make a back up copy before trying new code, you never know what you might lose! |
|
|
|
|
|
#9 |
|
Join Date: Sep 2004
Location: Hampshire, England
Posts: 3,822
|
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
__________________
Regards Jon (XP Pro v.2002, XL2003)
|
|
|
|
|
|
#10 |
|
Join Date: Oct 2006
Location: Bryan, TX
Posts: 14,397
|
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
__________________
The more we learn, and the better we get at our trade, the easier it becomes to overlook the obvious. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|