2 つの文字列を比較するために使用したいこのコードがあります。アイデアは、単語の最初の文字と数字の最後の 4 文字を取得し、それらを組み合わせて、別の単語と比較できるようにすることです。たとえば、「Smith John 123456」があり、「s3456」と入力したい場合、それを見つけることができるはずです。
Dim strFileName, strTxtValue
strFileName = "4ABCD_Delta_Jhon_T_JR_123456"
strTxtValue = "D3456"
Dim item, items, firstInitial, lastFour, myArray
strFileName = replace(strFileName,"_"," ")
myArray = Split(strFileName)
For Each item In myArray
If IsNumeric(item) Then
lastFour = Right(item, Len(item)-2)
Exit For
End If
Next
For Each items In myArray
firstInitial = Left(items, 1)&lastFour
If UCase(strTxtValue) = UCase(firstInitial) Then
Contains = True
End If
Next
これまでのところ、これは私が持っているものですが、機能させることができませんでした。誰か助けてくれませんか?