VBA & Macro Problems

Check Whether an Excel Cell Matches Multiple Values in VBA

Muhammad TalhaMuhammad Talha Nov 22, 2026 868 views

Question details

Check whether an Excel cell contains one of several allowed permission values in a VBA array.

Check Whether an Excel Cell Matches Multiple Allowed Values in VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, open the Developer tab and select Visual Basic, then choose Insert > Module.

2
Add the permission check

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

3
Run the macro

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.

Use Application.Match to search the allowed-values array
How the match works: A match returns a numeric position; a missing value returns an error value, so IsNumeric is false. Match is case-insensitive and can interpret wildcard characters such as * and ? in text lookup values.
Free Microsoft Office alternative

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.

Open and edit Excel XLSX and XLS spreadsheets.Review permission values in a familiar spreadsheet interface.Move everyday spreadsheet work to a free, lightweight Office suite.Use familiar menus and tools when switching from Microsoft Office.
microsoft office alternative - wps office

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.