To achieve the functionality of selecting a cell in Excel and highlighting other specific cells, you can use VBA (Visual Basic for Applications) to create a macro. This macro can be designed to respond to cell selections and highlight the desired cells accordingly. Here’s a basic example of how you can set this up:
- Open the VBA Editor: Press
ALT + F11in Excel to open the VBA editor. - Insert a Module: Right-click on any of the items in the Project Explorer, go to
Insert, and then clickModule. - Add the Following Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) ' Clear previous highlights Cells.Interior.ColorIndex = xlNone ' Highlight cells based on selection If Not Intersect(Target, Range("B3")) Is Nothing Then Range("C3, K4").Interior.Color = RGB(255, 255, 0) ' Yellow ElseIf Not Intersect(Target, Range("C3, K4")) Is Nothing Then Range("B3, C3, K4").Interior.Color = RGB(255, 255, 0) ' Yellow ElseIf Not Intersect(Target, Range("C12")) Is Nothing Then Range("L5, N19").Interior.Color = RGB(255, 255, 0) ' Yellow ElseIf Not Intersect(Target, Range("L5, N19")) Is Nothing Then Range("C12, L5, N19").Interior.Color = RGB(255, 255, 0) ' Yellow End If End Sub - Close the VBA Editor: Save your work and close the editor.
- Test the Macro: Now, when you click on the specified cells (B3, C3, K4, C12, L5, N19), the corresponding cells will highlight in yellow.
This code uses the Worksheet_SelectionChange event to check which cell is selected and highlights the specified cells accordingly. You can modify the ranges and colors as needed for your schedule.
References: