Matching part of a number

wackywoo105

Registered User.
Local time
Today, 12:40
Joined
Mar 14, 2014
Messages
203
I'm trying to match a number with a string that may contain the number.

e.g.

Hi = "07123456789"
Bye = "07098765432, 07123456789, 07102938475"

so if Hi is anywhere in Bye it returns true.

e.g. If "*" & Hi & "*" like Bye then msgbox "bingo"

However it never works and is always false, unless the 2 strings are identical. I've tried instr() also which I cant get to work.

For another function I split the Bye into an array to separate out the numbers and cycled through them, but would like an easier way if possible?

Can anyone suggest anything? Also why does this work for text but not for numbers?
 
Instr() should work but you need to ensure that you add a comma at the end (in order to use it as a delimiter to avoid finding false positives):
Code:
Hi = "07123456789"
Bye = "07098765432, 07123456789, 07102938475"

ByeComma:IIf(right([Bye],1)<>",",[Bye] & ",",[Bye])
IsHiInBye:Iif(Instr([ByeComma],[Hi] & ",")>0,True,False)

Cheers,
 
Keep in mind that using Like like that might give you some false positives, might not apply to you but consider this example:
Hi = "0712345678" 'notice I removed the last digit = 9
Bye = "07098765432, 07123456789, 07102938475"
If Bye Like "*" & Hi & "*" then msgbox "bingo" 'you would get bingo because Hi is indeed included in Bye but it is not equal to the entire "element" in Bye which has the trailing 9 I removed

Cheers,
 

Users who are viewing this thread

Back
Top Bottom