There's just a few concepts here at play, that I think if you understand, will make a lot more sense.
In VBA, it is important to understand the difference between literal text and variables.
Anything enclosed in double-quotes is treated as literal text (literally, the value
a).
In this example, a represent a variables (not literal text). So a must be defined (set to something). So before this section of code, you may see something like this:
This means that the variable
a is equal to whatever the value in cell C4 is.
So that is a brief description between the difference between variables and literal text.
Now, if you used the Macro Recorder, and recorded yourself filtering a data range for values that contain "a", and then looked at the code you just recorded, you would see criteria like this:
The asterisks indicate "wildcards". So what that means, is look for entries where it has "something" than and "a" and then something else after it (note that "something" can be "nothing). So it would return anything that has an "a" anywhere in it.
So now we have identified the pattern we want:
asterisk + what I am looking for + asterisk
Now, we already know from my first response, that in order to use C4 as our criteria, we use:
Code:
Criteria1:=Range("C4").Text
So now we just need to attach literal asterisks for the wild cards on each side of it. And to sew together multiple string items, we use the
& symbol.
So it would look like:"
Code:
Criteria1:="*" & Range("C4").Text & "*"
So hopefully, that makes sense, and you can see how we arrived there and how you can use the Macro Recorder to help figure out some of the code for you. It really is a helpful tool. Even us programmers who have been doing this for years use it often (as we don't have all the syntax of VBA committed to memory!).