I've been using VBA for the past month now (for my job) and since I've begun using this language/script, there have been several occurances where I have issues comparing strings.. the ways that I've compared strings so far are:
- str1 = str2 and str1 <> str2
- StrComp(str1, str2, comparisonMethod)
- InStr(str1, str2)
Sometimes, before using one of these comparison methods, I'll first apply UCase(str1), or even UCase(Trim(str1)). From my experience so far though, comparing strings in VBA seems to be a rather fickle thing, because I feel like I get inconsistent results.
QUESTION: What is the best procedure for comparing two strings in VBA?
For example: Imagine there are two lists.. one list contains laptop models, the other contains parts numbers. The goal is to associate all part numbers with a model. My results produce only partial associations, meaning that if I have 10 part numbers that should associate with a model, only 5 or 6 actually are. I then take the strings that don't properly compare and compare again in seperate code, and will then get the correct result. This kind of behavior has been somewhat consistent throughout my use of VBA, and is where the "feeling" comes from.