Toggle an X in an Excel Cell with a Mouse Click
Question details
The user wants to toggle an X in an Excel cell by selecting it with the mouse.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet needs a clickable range where selecting a cell adds or removes an X.
- Observed behavior
- Selecting a cell in the specified range should add an X or clear an existing X.
Open the workbook in desktop Excel and choose the cells to use as toggles. Use empty cells: the macro will replace any other contents in the target range with an X.
Add a SelectionChange macro to the worksheet
Use a worksheet event to toggle an X when a single cell in a specified range becomes selected.
Right-click the worksheet tab and select View Code to open that sheet's VBA code module.
Paste this code into the worksheet module, replacing A1:A10 with your desired range: Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.CountLarge > 1 Then Exit Sub If Not Intersect(Target, Me.Range("A1:A10")) Is Nothing Then If Target.Value = "X" Then Target.ClearContents Else Target.Value = "X" End If End If End Sub
In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). If prompted when reopening a trusted workbook, select Enable Content to allow its macros to run.
Click a cell in the target range to add an X. Select a different cell, then click the original cell again to remove the X.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move existing workbooks. It does not replace the Excel-specific VBA setup described above; macro support can vary by version.

Frequently Asked Questions
Why doesn't clicking the same cell again remove the X?
The macro runs only when the selection changes. Click a different cell first, then click the original cell again.
How do I change which cells act as toggles?
Right-click the worksheet tab, select View Code, and replace A1:A10 in Me.Range("A1:A10") with your chosen range.
Will this macro overwrite existing cell contents?
Yes. If a target cell does not contain X, the macro replaces its contents with X. If it contains X, the macro clears the contents.
Can I run this macro in Excel for the web?
No. VBA macros do not run in Excel for the web. Open the macro-enabled workbook in desktop Excel and enable macros if you trust the file.




