I'm new to vba functions, but I have read the documentation and I am still getting a "Type Mismatch," and I can't figure out why. I am taking the value entered into a combobox, assigning it to a string value (strCityName) and trying to determine if it has a space (a space character) within it.
When I run this it tells me the list where I call InStr has a "Type Mismatch." InStr is supposed to return a 0 as a "Variant Long" value if there is no match and the starting position of the match if one is found. I've declared hasSpace as a Variant (and also As Long - but with the same error showing).
InStr is supposed to take a String value, and I've defined strCityName as a string. Why am I getting a type mismatch?!
Dim hasSpace As Variant
Dim strCityName As String
strCityName = boxCity.Value 'define string
hasSpace = InStr(strCityName, " ", 1)
If hasSpace > 0 Then
MsgBox "space detected"
End If
Bookmarks