Want: cross hair highlit in my excel sheet

Chaturvedi, Santosh 340 Reputation points
2026-06-22T14:32:04.58+00:00

Hello - I want to install or cretate VBA for cross hair highlit in my excel sheet. please provide me the ways to do that i can see cross hair highlights when i open my ecel sheet.

User's image

Developer technologies | Visual Basic for Applications
0 comments No comments

Answer accepted by question author
Nancy Vo (WICLOUD CORPORATION) 8,155 Reputation points Microsoft External Staff Moderator
2026-06-23T03:26:07.04+00:00

Hello @Chaturvedi, Santosh .

Thanks for your question.

To make the crosshair highlight functional for all sheets within your selected workbook,I recommend moving your VBA code from a specific worksheet module into the ThisWorkbook module.

  1. Using the Workbook_SheetSelectionChange event.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

    Sh.Cells.Interior.ColorIndex = xlNone

 

    Target.EntireRow.Interior.Color = RGB(255, 200, 200)

    Target.EntireColumn.Interior.Color = RGB(255, 200, 200)

End Sub


  1. How to install the code
  • Open your Excel workbook.
  • Press ALT + F11 to open the VBA Editor.
  • In the "Project" window on the left-hand side, look for your workbook's name.
  • Underneath it, double-click on the object named ThisWorkbook. (Do not paste this into Sheet1, Module1, ...)
  • Paste the code above into the large white code window on the right.
  • Close the VBA Editor and save your file as an Excel Macro-Enabled Workbook (\*.xlsm).

Note: Applying cell interior colors via VBA like this will override and clear any custom background colors you have manually applied to cells. Additionally, running VBA macros automatically clears your "Undo" history. If you rely on manually color-coding cells or using the Undo button frequently, you may want to explore Conditional Formatting as an alternative approach.

I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

4 additional answers

Sort by: Newest
  1. Chaturvedi, Santosh 340 Reputation points
    2026-06-23T07:15:55.3933333+00:00

    MY workbook have 150 sheets with different names.

    I want to the below VBA code applicable for the work book having 150 sheets.

    How to the below VBA coomon to all 15o sheets at once.

    The vba code is as shown below


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Application.ScreenUpdating = False
    
    ' Clear existing highlights on this sheet
    
    Cells.Interior.ColorIndex = 0
    
    ' Highlight the entire row and column of the active cell
    
    With Target
    
        .EntireRow.Interior.ColorIndex = 36   ' light color for row
    
        .EntireColumn.Interior.ColorIndex = 36 ' same color for column
    
    End With
    
    Application.ScreenUpdating = True
    

    End Sub

    Was this answer helpful?


  2. Viorel 127.3K Reputation points
    2026-06-22T15:12:42.0333333+00:00

    Modern Excel has an option in the View tab of Ribbon: Focus Cell.

    Was this answer helpful?

    0 comments No comments

  3. Chaturvedi, Santosh 340 Reputation points
    2026-06-22T14:51:56.0833333+00:00

    This VBA is working - But if i want to make functional for all sheets in the selected work book how to make it

    Was this answer helpful?

    0 comments No comments

  4. AI answer

    2026-06-22T14:32:22.24+00:00

    Use the Worksheet_SelectionChange event to draw a “cross hair” (row + column highlight) whenever a cell is selected.

    Below is a simple example that:

    • Clears previous highlighting on each selection change.
    • Highlights the entire row and column of the active cell.
    • Runs automatically whenever the sheet is used (no button needed).

    Steps

    1. Open Excel and the workbook.
    2. Press Alt+F11 to open the VBA Editor.
    3. In the Project pane, double‑click the worksheet where the cross hair is needed (for example, Sheet1).
    4. Paste this code into the code window for that sheet:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Application.ScreenUpdating = False
    
        ' Clear existing highlights on this sheet
        Cells.Interior.ColorIndex = 0
    
        ' Highlight the entire row and column of the active cell
        With Target
            .EntireRow.Interior.ColorIndex = 36   ' light color for row
            .EntireColumn.Interior.ColorIndex = 36 ' same color for column
        End With
    
        Application.ScreenUpdating = True
    End Sub
    
    1. Close the VBA editor and return to Excel.
    2. Save the workbook as a macro‑enabled file (.xlsm).
    3. Reopen the workbook and enable macros when prompted.

    Now, whenever a cell is selected on that worksheet, its entire row and column will be highlighted, creating a cross‑hair effect similar to the one shown in the image.

    To change the highlight color, adjust the ColorIndex value (for example, 6 for yellow, 8 for turquoise, etc.).


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.