View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
sugargenius sugargenius is offline
external usenet poster
 
Posts: 26
Default match function with text and numbers


Gary''s Student wrote:
I got you data to work. msgbox(res) returned 1 for "AA" and returned 14 for
"99"

Just be sure that the 99 is really a text value. I copied and pasted right
from your posting. When I expanded the text-to-columns, I told the wizard to
treat the first column as text. That way the 99 is just as "find-able" as
any other string.
--
Gary's Student


"sugargenius" wrote:


Gary''s Student wrote:
Always use a string

Dim s as String
s = "AA"
call LookupNLHand(s)
s="99"
call LookupNLHand(s)
--
Gary's Student


Using your examples, "AA" works fine but "99" throws error 2042 on the
vlookup


This is the only way I could get it to work:

Sub LookupNLHand(sStartingHand As Variant)
Dim res As Variant, Hand As HoldemHand, rngLookup As Range, sMsg As
String
Set rngLookup = Range("STARTING_HANDS_LOOKUP")

If Not IsNumeric(sStartingHand) Then
'res = Application.VLookup(sStartingHand, rngLookup, 5, False)
res = Application.Match(sStartingHand, rngLookup)
Else
res = Application.Match(CInt(sStartingHand), rngLookup)
End If

If IsError(res) Then
MsgBox "Could not locate that starting hand!"
Exit Sub
End If

With Hand
.iRank = res
.iGroup = rngLookup(res, GROUP_COL)
.sPosition = rngLookup(res, POSITION_COL)
.sStrategy = rngLookup(res, STRATEGY_COL)
End With

sMsg = "Your hand is ranked " & Hand.iRank & vbCrLf & _
"It is in group " & Hand.iGroup & vbCrLf & _
"You should only play this if you are in " & Hand.sPosition & "
position" & vbCrLf & _
"Or, playing " & Hand.sStrategy

MsgBox sMsg

End Sub