An implementation of Visual Basic that is built into Microsoft products.
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.
- 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
- 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.