craigexcel
Active Member
- Joined
- Jun 28, 2006
- Messages
- 298
- Office Version
- 2016
- Platform
- Windows
I found this code that will automatically shade both the row and column of the cell that has the focus. I'd like for this action to happen for ANY wkbk that is opened. Since it seems that would require the use of "'Private Sub Workbook_Open()", is there a way to make this work? I had put this code in the Workbook object of ThisWorkbook.
Code:
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
'automatically shades row AND column of selected cell
Static xRow
Static xColumn
If xColumn <> "" Then
With Columns(xColumn).Interior
.ColorIndex = xlNone
End With
With Rows(xRow).Interior
.ColorIndex = xlNone
End With
End If
pRow = Selection.Row
pColumn = Selection.Column
xRow = pRow
xColumn = pColumn
With Columns(pColumn).Interior
.ColorIndex = 24
.Pattern = xlSolid
End With
With Rows(pRow).Interior
.ColorIndex = 38
.Pattern = xlSolid
End With
End Sub