How to highlight the active cell or selection in Excel?
Working with large, complex worksheets in Excel often makes it difficult to quickly locate the active cell or recognize the currently selected range. When you're navigating data, especially for reviewing or editing specific values, losing track of your position can lead to errors or inefficient workflows. By automatically applying a distinctive color to your active cell or selection, you can easily spot your current location, reducing mistakes and saving time. This tutorial provides practical methods for making active cells or selected ranges visually stand out as you move through a worksheet, helping you maintain your focus and accuracy in various data management scenarios.
Highlight the active cell or selection with VBA code
Highlight the active cell or selection with VBA code
One effective way to dynamically highlight the active cell or selected group of cells is to use VBA programming within Excel. This approach is ideal for users who want real-time visual feedback while working across multiple sheets or with large sets of data. The setting is flexible: after implementation, your active selection will always be shaded with your preferred color, making it much easier to find at a glance.
1. Begin by holding down ALT + F11 on your keyboard. This will open the Microsoft Visual Basic for Applications window, where you can manage and edit code modules for your Excel workbook.
2. In the left-side Project Explorer pane, locate your workbook name. Expand its folders if necessary, then double-click ThisWorkbook to open its code module. If you cannot see the Project Explorer pane, click View > Project Explorer from the VBA window’s menu bar to display it.
Once the ThisWorkbook code area is open, copy and paste the following VBA code into the blank module space:
VBA code: Highlight active cell or selection
Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
'UpdatebyExtendoffice
Static xLastRng As Range
On Error Resume Next
Target.Interior.ColorIndex = 6
xLastRng.Interior.ColorIndex = xlColorIndexNone
Set xLastRng = Target
End Sub 
3. After inserting the code, save your changes and close the VBA editor window to return to your worksheet. Now, whenever you select a cell or a range of cells, those cells will be highlighted automatically with the chosen color. The highlighted area updates instantly along with your selection, ensuring you always know exactly which cells are active.
To help ensure you get the best results, take note of the following usage advice and tips:
1. If the Project Explorer Pane isn’t visible, click the View option in VBA, and select Project Explorer to reveal the panel where you’ll find ThisWorkbook.
2. Within the provided code, the line .ColorIndex =6 controls the highlight color. You can modify this value to set your preferred color. Some common ColorIndex values are 3 (red),4 (green),5 (blue),6 (yellow), etc. Refer to Excel’s full color index list for more options and experiment as needed to suit your visual preferences.
3. This VBA method applies to all worksheets in your workbook, meaning any sheet where you select cells will have the highlight feature active. It’s useful when reviewing data across different sheets.
4. Be aware that cells highlighted by this VBA code will be temporarily colored according to your selection. If you have cells that were previously filled with custom colors and then select them, their original colors will be removed when you move the selection away. Carefully consider this if you have important formatting you don’t want to lose. To avoid losing existing cell colors, you may wish to manually note or duplicate color formatting before applying this solution.
Some additional troubleshooting advice: If you encounter unexpected errors or the code does not work as intended, please confirm that macros are enabled in Excel and that you have permission to run VBA code. Ensure there are no conflicting conditional formatting rules that could override your highlight settings. If highlights do not appear, try re-selecting another cell or reloading the workbook to refresh the VBA code’s effect.
Overall, using VBA for dynamic highlighting is especially valuable for auditing, editing, and presenting data in large spreadsheets, though it may not preserve custom cell formatting. For users seeking different visual approaches or simpler alternatives that preserve colors, there are other practical methods worth considering:
- You can use Conditional Formatting in Excel to highlight specific cells, rows, or ranges based on selection criteria or cell values. This method is more suitable for highlighting based on rules rather than direct selection, but it preserves other formatting and is easy to set up.
- Some third-party Excel add-ins, such as Kutools for Excel, offer convenient one-click features for quickly highlighting active cells or ranges. These tools often preserve previous formatting and simplify the customization process.
Related article:
How to auto-highlight rows and columns of the active cell in Excel?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
All Kutools add-ins. One installer
Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.
- All-in-one suite — Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
- One installer, one license — set up in minutes (MSI-ready)
- Works better together — streamlined productivity across Office apps
- 30-day full-featured trial — no registration, no credit card
- Best value — save vs buying individual add-in