Automatically Highlight the Active or Selected Cell

Add to Favorites
Author:

This macro will highlight the active cell in any excel spreadsheet with a color selected in the code. This means that any cell you select will be highlighted in a way that fills the cell in with color. This will also highlight any selection of cells from one to as many as you select and once you click away the highlight will disappear. This is great for giving presentations of for showing someone how to do something in excel, but only for worksheets with not previously colored cells - see Note.

Note: Using this macro will not allow you to apply background color to any cells in the workbook where this is used. This means that you will not be able to assign colors to particular cells unless you remove the macro. Additionally, any previously colored cells that are clicked on when this macro is being used will lose all color after the active cell moves to another cell. This means you will quickly lose the color for cells in previously colored worksheets.

Where to install the macro:  ThisWorkbook

Automatically Highlight the Active or Selected Cell

Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)

'Change the NUMBER in the line of code reading
'"Target.Interior.ColorIndex = 3 " in order to get a
'different color to highlight the active cell.

Static OldRange As Range

On Error Resume Next

Target.Interior.ColorIndex = 3

OldRange.Interior.ColorIndex = xlColorIndexNone

Set OldRange = Target
End Sub





Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Similar Content on TeachExcel
Print Preview Screen Display for The Current or Selected Worksheets in Excel
Macro: This free Excel macro allows you to display the print preview screen or window for the cur...
Highlight the Row and Column of the Selected Cell
Macro: This macro will highlight the row and column of the active cell. This will fill the column...
Highlight the Row of the Selected Cell
Macro: This macro will highlight the row and column of the active cell. This will fill the row of...
Highlight the Column of the Selected Cell
Macro: This macro will highlight the column of the active cell. This will fill the column of...
Highlight Rows that Meet a Certain Condition in Excel
Tutorial: In this tutorial I am going to cover how to highlight rows that meet a certain condition. ...
Highlight Duplicate Values in Excel
Tutorial: How to highlight duplicate values in a list. Also, how to arrange those values next to ea...


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.

Tutorial Details
Similar Content
Print Preview Screen Display for The Current or Selected Worksheets in Excel
Macro: This free Excel macro allows you to display the print preview screen or window for the cur...
Highlight the Row and Column of the Selected Cell
Macro: This macro will highlight the row and column of the active cell. This will fill the column...
Highlight the Row of the Selected Cell
Macro: This macro will highlight the row and column of the active cell. This will fill the row of...
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course