logo
search
VBA & Macro Problems

How to Highlight and Zoom the Active Excel Cell Using VBA Code

Maira MehtabMaira Mehtab Sep 21, 2026 872 views

Question details

The user needs a VBA macro to automatically highlight the currently selected cell in yellow and zoom the worksheet to 125% for a presentation. The effects should reset when multiple cells are selected or when switching worksheets.

Product
Excel
Device & OS
not provided
Scenario
Presenting spreadsheet data to an audience where dynamically drawing focus to the active cell improves visibility and tracking.
Observed behavior
Requires a script that applies conditional background color and zoom levels upon cell selection while restoring previous states when moving to a new cell.
Before you start

Before applying this VBA code, ensure you have the Developer tab enabled in your spreadsheet application and save your file as a Macro-Enabled Workbook to prevent losing your script.

Solution 1Recommended

Apply VBA Code to the ThisWorkbook Module

Use this VBA script to automatically trigger the highlight and zoom effect whenever a single cell is selected in the workbook.

This method utilizes the Worksheet_SelectionChange event to detect when a new cell is activated. It dynamically restores the previous cell's color, applies a yellow highlight to the new active cell, and adjusts the window zoom to 125%. If multiple cells are selected, the zoom reverts to normal.

1
Open the Visual Basic Editor

Open your workbook and press ALT + F11 on your keyboard to launch the Visual Basic Editor.

2
Access ThisWorkbook

In the Project Explorer pane on the left side, locate your workbook name and double-click on 'ThisWorkbook'.

3
Paste the VBA Code

Paste your custom highlight and zoom VBA script into the code window. Ensure it includes the logic to reset zoom to 100 percent when Target.Cells.Count is greater than 1.

4
Test the Macro

Close the Visual Basic Editor, return to your worksheet, and click on any single cell to verify the yellow highlight and 125% zoom apply correctly.

Important Limitation: Running this VBA macro will completely disable Excel's Undo functionality. It is highly recommended to use this approach strictly for presentation purposes and not during data entry.
Advanced Spreadsheet Editing

Use WPS Office to Run VBA Macros for Presentations

WPS Spreadsheet provides powerful support for VBA macros, allowing you to easily run presentation scripts like highlighting active cells and dynamic zooming. It is a lightweight, highly compatible alternative for all your data processing needs.

  1. 1. Open WPS Spreadsheet: Launch WPS Office and open the workbook you plan to use for your presentation.
  2. 2. Access the Developer Tab: Navigate to the Developer tab on the top ribbon and click on 'Visual Basic', or use the ALT + F11 shortcut.
  3. 3. Insert the Code: Double-click 'ThisWorkbook' in the project pane, paste your selection-change VBA script, and close the editor.
  4. 4. Save as Macro-Enabled: Go to Menu > Save As, and choose 'Macro-Enabled Workbook (*.xlsm)' to ensure your VBA code is preserved.
Seamlessly execute standard VBA codes and macrosFully compatible with Microsoft Excel .xlsm and .xlsb formatsLightweight design with fast loading speeds for live presentationsClean, familiar user interface for effortless navigation
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Undo button stop working after using this VBA code?

In most spreadsheet programs, running a VBA macro that modifies the worksheet environment (such as changing cell background colors) automatically clears the Undo history stack. Because of this, the script is best reserved for presentations rather than active editing.

How do I stop the worksheet from zooming when I select multiple cells?

Your VBA code should include a condition checking the selection count, such as 'If Target.Cells.Count > 1'. Within this block, you can instruct the macro to set the ActiveWindow.Zoom to 100 and exit the subroutine.

Can I change the highlight color from yellow to another color?

Yes, you can easily change the color by modifying the 'ColorIndex' value in your VBA script. Yellow is typically ColorIndex 6. You can replace this number with the standard index of your preferred color to match your presentation theme.