Display a Message Box for Specific Text in Excel
Question details
Display different message boxes when specific text is entered in a worksheet range without creating duplicate event procedures.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user enters Scope, Token, Chip, or Relax in cells A2:A200 and wants Excel to show a corresponding message.
- Observed behavior
- Multiple Worksheet_Change procedures cause an Ambiguous name detected error, and the event cannot be run like a standard macro.
Identify the worksheet and range where entries should trigger a message. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros if prompted when you open it.
Use one Worksheet_Change event for all matching text
Combine the text checks in the worksheet's existing change event to avoid duplicate procedure names.
Right-click the tab of the worksheet where users enter the text and select View Code. In the VBA editor, use that worksheet's code window rather than a standard module.
In the worksheet code window, find any procedures named Worksheet_Change. Keep only one declaration and combine any existing logic you still need inside it. Remove any separate Sub Scope procedure created for this task.
In the worksheet code window, use the following event code. If you already have a Worksheet_Change procedure, merge the checks into it instead of adding a second event: Private Sub Worksheet_Change(ByVal Target As Range) Dim changedCells As Range Dim cell As Range Set changedCells = Intersect(Target, Me.Range("A2:A200")) If changedCells Is Nothing Then Exit Sub For Each cell In changedCells.Cells If Not IsError(cell.Value) Then Select Case UCase(Trim(CStr(cell.Value))) Case "SCOPE" MsgBox "Scope was entered." Case "TOKEN" MsgBox "Token was entered." Case "CHIP" MsgBox "Chip was entered." Case "RELAX" MsgBox "Relax was entered." End Select End If Next cell End Sub
Return to the worksheet and enter Scope in a cell within A2:A200. The message should appear automatically; do not run Worksheet_Change from the Macros dialog. Replace the sample message text in each MsgBox line as needed.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Microsoft Excel formats, making it easy to move everyday workbook tasks between office suites. It does not resolve Excel's VBA errors; macro support can vary.

Frequently Asked Questions
Why does Excel say Ambiguous name detected: Worksheet_Change?
The same worksheet module may contain more than one Worksheet_Change procedure. Right-click the worksheet tab, select View Code, and combine the required logic into a single event procedure.
Why does Excel ask me to create a macro when I try to run the event?
Worksheet_Change is an event procedure, not a standard macro to run from the Macros dialog. Enter or paste a matching value into A2:A200 on the worksheet to trigger it.
Why doesn't a message appear when I enter Scope?
Check that the code is in the correct worksheet module, the entry is in A2:A200, and macros are enabled. Also check whether events have been disabled elsewhere in the workbook; in the VBA editor's Immediate window, you can enter Application.EnableEvents = True.
Will the event run when a formula result changes?
Worksheet_Change responds to changes to cells, such as typing or pasting, but not to a formula result changing during recalculation. Formula-result monitoring requires a different approach, such as the Worksheet_Calculate event.




