Created
April 15, 2016 08:24
Star
You must be signed in to star a gist
This subroutine highlights columns on a calendar in Excel based on the selected activity by leveraging the Worksheet_SelectionChange event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Private Sub Worksheet_SelectionChange(ByVal Target As Range) | |
'Set the context appropriately using With...End With | |
With Sheets("calendar") | |
'Clear all previously-applied highlighting for easy readability | |
.Cells.Interior.ColorIndex = xlColorIndexNone | |
'Switch on the address of the selected cell | |
Select Case Target.Address | |
Case "$A$1" '<~ if cell A1 is clicked, highlight cells C5-C9 yellow | |
.Range("C5:C9").Interior.Color = RGB(255, 255, 0) | |
Case "$A$2" '<~ if cell A2 is clicked, highlight cell D5-D9 green | |
.Range("D5:D9").Interior.Color = RGB(0, 255, 0) | |
Case "$A$3" '<~ if cell A3 is clicked, highlight cell E5-E9 orange | |
.Range("E5:E9").Interior.Color = RGB(255, 165, 0) | |
End Select | |
End With | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment