Tom’s Tutorials For Excel: Highlighting the Current and Prior Selected Cells.

Tom’s Tutorials For Excel: Highlighting the Current and Prior Selected Cells.

I previously posted this example for highlighting the selected cell.

Today, here is how you can highlight not only the current cell, but the cell you’d selected before you selected your current cell. To make it easy to distinguish between the two cells, the currently selected cell is colored cyan, and the prior selected cell is colored magenta.

Take a look at the next two pictures. In the first picture, cell C5 is the active (currently selected) cell. You can tell by its cyan color, and also you can see its address in the address bar. Before this picture was taken, cell H12 had been selected, evidenced by its magenta color.



This next picture shows that the currently selected cell is L18, colored cyan. Notice that now, cell C5, which was selected before as seen in the first picture, is colored magenta.



Here is the code that accomplishes this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = 0
Static PriorCell As Range
If Not PriorCell Is Nothing Then PriorCell.Interior.Color = vbMagenta
Target.Interior.Color = vbCyan
Set PriorCell = Target
End Sub

Here are the steps to install the code:

Step 1


Step 2
Copy the above code and paste it into the worksheet module where shown.



Step 3
Press Alt+Q on your keyboard to return to your worksheet.

Share Button
Posted in Tom's Tutorials for Excel
Tags: , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*