To test whether a value a exists in a list like b, c in VBA Excel, the shortest reliable method is the Application.Match function wrapped in IsNumeric. For example, If IsNumeric(Application.Match(a, Array("b", "c"), 0)) Then runs your code only when a matches one of the items. You can also use a Select Case statement, a For Each loop over an array, or the InStr function for a single text string. The right choice depends on whether your list is a fixed set of literals, a range of cells, or a long dynamic array. This guide walks through each working method, explains when to use it, and covers the errors that trip people up.

What You'll Need

  • Excel with the Developer tab enabled (File > Options > Customize Ribbon > check Developer).
  • A basic familiarity with opening the VBA editor (Alt+F11) and inserting a module (Insert > Module).
  • Your list values ready as either literals, a worksheet range, or an array.

Step-by-Step

  1. Open the VBA editor and insert a module. Press Alt+F11, then choose Insert > Module. All code below goes into this module.
  2. Decide on your list format. If the list is a small fixed set like "b" and "c", use an Array. If it lives in cells (say A1:A10), use a Range. If it is long and changes at runtime, build a Variant array first.
  3. Method 1 – Application.Match with IsNumeric. This is the fastest one-liner for arrays and ranges. Example:
    Dim a As String
    a = "b"
    If IsNumeric(Application.Match(a, Array("b", "c"), 0)) Then
        MsgBox "Found"
    Else
        MsgBox "Not found"
    End If
    The third argument 0 means exact match. Match returns an error if not found, so IsNumeric converts that error into a clean False.
  4. Method 2 – Select Case. Best for a short, readable list of literals. Example:
    Select Case a
        Case "b", "c"
            MsgBox "Found"
        Case Else
            MsgBox "Not found"
    End Select
    This avoids arrays entirely and is easy to read for two or three values.
  5. Method 3 – Loop over an array. Use this when you need to do something with the matched item or when the list is built dynamically. Example:
    Dim arr As Variant, item As Variant, found As Boolean
    arr = Array("b", "c")
    found = False
    For Each item In arr
        If item = a Then
            found = True
            Exit For
        End If
    Next item
    If found Then MsgBox "Found"
  6. Method 4 – InStr for a single text string. If your "list" is really one string like "b c", use If InStr(1, "b c", a, vbTextCompare) > 0 Then. Be careful: this matches substrings, so "b" would also match inside "bb". Add spaces around values or use delimiters to avoid false positives.
  7. Test with edge cases. Run your macro with a set to a matching value, a non-matching value, an empty string, and a value with different case. Confirm the result is what you expect. Note that Application.Match is case-insensitive by default; InStr with vbTextCompare is also case-insensitive, while a plain = comparison in VBA is case-sensitive unless Option Compare Text is set at the top of the module.

Common Mistakes

  • Forgetting the third argument in Match. Omitting the 0 makes Match default to 1 (less than or equal), which can return a wrong position for unsorted lists.
  • Not wrapping Match in IsNumeric or error handling. If the value is not found, Match raises error 2042. Without IsNumeric or On Error Resume Next, your macro stops.
  • Using InStr without delimiters. Searching for "a" in "cat" returns a match even though "a" is not a list item. Always pad the list and search string with spaces or use a proper array.
  • Assuming case sensitivity. VBA string comparisons are case-sensitive by default. If your list has "B" and you search for "b", a plain = loop will not match. Use LCase or StrComp with vbTextCompare.
  • Passing a Range to Match incorrectly. Match expects a one-dimensional array. A single-column range works, but a multi-column range does not. Use Application.Transpose or loop instead.

Tips

  • For lists of 10 or fewer literals, Select Case is the most readable and fastest to write.
  • For lists stored in cells, read the range into a Variant array once (arr = Range("A1:A100").Value) and loop; this is much faster than reading cells one by one.
  • Use Option Compare Text at the top of the module if you want all string comparisons in that module to be case-insensitive.
  • When using Application.Match, remember it is a worksheet function: it returns a Double or an error, never a Boolean. Always test with IsNumeric or IsError.
  • If your list contains numbers stored as text, Match may fail. Convert both sides with CStr or CLng before comparing.

Troubleshooting

If your macro stops with "Run-time error 13: Type mismatch", check that the variable a is the same type as the list items. Match returns an error when types differ. If you get "Run-time error 2042", you forgot to wrap Match in IsNumeric or IsError. If the result is always False even when you know the value exists, check for leading or trailing spaces with Trim, and confirm case sensitivity. If Select Case never matches, verify that the Case values are comma-separated and quoted correctly. If InStr returns a match you did not expect, you are hitting a substring; switch to an array-based method. If your list is in a worksheet and Match returns #N/A, confirm the range is a single column or row. Finally, if nothing works, step through the code with F8 and use the Immediate Window (Debug.Print a) to see exactly what value is being tested.

Frequently Asked Questions

Can I check if a value is in a list without a loop?

Yes. Application.Match with IsNumeric is a one-line, loop-free check for arrays and ranges.

Is Application.Match case-sensitive?

No, it is case-insensitive by default. If you need case-sensitive matching, use Application.Match with 0 and compare the exact case manually, or use a loop with StrComp(..., vbBinaryCompare).

What if my list is in a different worksheet?

Qualify the range fully, for example Worksheets("Sheet2").Range("A1:A10"). Match works across sheets as long as the sheet is specified.

Why does InStr match part of a word?

InStr searches for a substring, not a whole item. Add spaces or delimiters around list items and the search value, or use an array-based method instead.

Can I use this to check multiple values at once?

Not directly. Loop through your test values and run the check for each one, or use Application.CountIf on a range to count matches.