View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Joerg Joerg is offline
external usenet poster
 
Posts: 138
Default How to change entire row colour when row is selected?


"NickHK" wrote in message
...
Something like this, so only the first row is changed, if you select
multiple rows:

Dim OldRange As Range

Private Sub Worksheet_Activate()
Set OldRange = ActiveCell.Range("A1")
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Clear the old formatting
With OldRange.EntireRow.Font
.ColorIndex = xlAutomatic
.Bold = False
End With
'Set the new formatting
With Target.Range("A1").EntireRow.Font
.ColorIndex = 3
.Bold = True
End With
'Reset the range
Set OldRange = Target.Range("A1")
End Sub

NickHK




I changed above solution a bit. The following code "remembers" every
previous selected row and changes fonts back automatically (code goes into
code page of sheet):

Dim Oldaddress As String

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Oldaddress = "" Then Oldaddress = ActiveCell.Address 'Initialize
Oldaddress
'Set the new formatting
With ActiveCell.EntireRow.Font
.ColorIndex = 3
.Bold = True
End With
If Range(Oldaddress).EntireRow.Address < ActiveCell.EntireRow.Address
Then
With Range(Oldaddress).EntireRow.Font
.ColorIndex = xlAutomatic
.Bold = False
End With
End If
Oldaddress = ActiveCell.Address
End Sub

Cheers,
Joerg