Hi Programmers,
I'd like to not only highlight the active row, but also highlight the active cell with bold formatting. I'm using the code from this thread: Highlight Active Row macro error; http://www.excelforum.com/excel-prog...ro-error.html; but don't know how to adapt it.
Also, if cells happen to already be highlighted or formatted bold, the code should not interfere with this prior formatting.
Is this possible?
Lastly, the worksheet should reset to the prior formatting.
Thanks a bunch.
' HIGHLIGHT THE ENTIRE ROW YOU HAVE HIGHLIGHTED (ONLY USE ON SHEETS WITH COLOR/FORMATTING COMPLETE)
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Const cnNUMCOLS As Long = 100
Const cnHIGHLIGHTCOLOR As Long = 36 'default lt. yellow
Static rOld As Range
Static nColorIndices(1 To cnNUMCOLS) As Long
Dim i As Long
If Not rOld Is Nothing Then 'Restore color indices
With rOld.Cells
If .Row = ActiveCell.Row Then Exit Sub 'same row, don't restore
For i = 1 To cnNUMCOLS
With .Item(i)
.Interior.ColorIndex = nColorIndices(i)
.Font.Bold = False
End With
Next i
End With
End If
Set rOld = Cells(ActiveCell.Row, 1).Resize(1, cnNUMCOLS)
With rOld
For i = 1 To cnNUMCOLS
nColorIndices(i) = .Item(i).Interior.ColorIndex
Next i
.Interior.ColorIndex = cnHIGHLIGHTCOLOR
.Font.Bold = True
End With
' Cells(ActiveCell.Row, "C").Interior.ColorIndex = nColorIndices(3)
End Sub
Bookmarks