Check Whether an Excel Cell Matches Multiple Values in VBA
Question details
Check whether an Excel cell contains one of several allowed permission values in a VBA array.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A macro needs to approve a user only when a permission cell matches a value such as SuperAdmin or Admin.
- Observed behavior
- An array created with VBA Array cannot be compared directly with a cell value using the equals operator.
Identify the cell containing the permission and the allowed values you want to check. The example below reads the cell five columns to the right of the active cell; adjust the reference to match your worksheet.
Use Application.Match to search the allowed-values array
Use this approach to check whether a permission value appears in a VBA array without comparing the entire array to the cell.
In Excel, open the Developer tab and select Visual Basic, then choose Insert > Module.
Paste this example into the module: Sub CheckPermission() Dim AllowedUsers As Variant Dim PermissionCell As Range AllowedUsers = Array("SuperAdmin", "Admin") Set PermissionCell = ActiveCell.Offset(0, 5) If IsNumeric(Application.Match(PermissionCell.Value, AllowedUsers, 0)) Then MsgBox "Permission is allowed." Else MsgBox "Permission is not allowed." End If End Sub
Select a worksheet cell five columns to the left of the permission value, then run CheckPermission from Developer > Macros. Replace the message boxes with your approval logic if needed.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface for opening and editing spreadsheets. Its Excel format compatibility can help you move everyday files between applications, but check VBA macro support in your WPS edition before relying on this Excel-specific solution.

Frequently Asked Questions
Why can't I compare the cell directly with the array?
The equals operator compares values; it does not search a VBA array for a matching element. Use Application.Match with the cell value, the array, and 0 to search for a match.
What does the 0 in Application.Match mean?
The third argument, 0, requests an exact match rather than an approximate match. For text lookup values, Excel may still interpret * and ? as wildcards.
Does Application.Match distinguish between Admin and admin?
No. Application.Match is case-insensitive for text. If capitalization must matter, loop through the array and compare each value with StrComp using vbBinaryCompare.
How do I check a different permission cell?
Change the reference in Set PermissionCell = ActiveCell.Offset(0, 5). For example, use ActiveCell.Offset(0, 2) to check the cell two columns to the right.




