郵便番号をコンマで分割してから、1 つずつ移動して一致を探す必要があります。
コードは次のようになります。
Dim strPostCode, strInput, x
Dim arrPostCodes, curPostCode, blnFoundMatch
strPostCode = "HS1,HS2,HS3,HS4,HS5,HS6,HS7,HS8,HS9,IV41,IV42"
strInput = "HS24AB"
arrPostCodes = Split(strPostCode, ",")
blnFoundMatch = False
For x=0 To UBound(arrPostCodes)
curPostCode = arrPostCodes(x)
'If Left(strInput, Len(curPostCode))=curPostCode Then
If InStr(strInput, curPostCode)>0 Then
blnFoundMatch = True
Exit For
End If
Next
Erase arrPostCodes
If blnFoundMatch Then
'match found, do something...
End If
上記は、ユーザー入力の任意の場所の各郵便番号を検索します。たとえば、「4AB HS2」も一致を返します。郵便番号を入力の先頭にのみ表示する場合はIf
、上記のコードで言及されている代替行を使用します。