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

Another one, which will at least maintain Undo and the clipboard while
selecting other cells in the same row. But select a cell in a different
column and both lost. Also not necessary to maintain a reference to the
previously formatted row.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim v As Variant

With Target(1).EntireRow.Font
v = .ColorIndex
If v < 3 Or IsNull(v) Then
With Cells.Font
.ColorIndex = xlAutomatic
.Bold = False
End With
.ColorIndex = 3
.Bold = True
End If
End With

End Sub

To maintain the clipboard while selecting in a different column bracket the
code with
If Application.CutCopyMode = 0 Then
'code
end if

Obviously with this method not possible to maintain colour & bold formats,
but there are other ways of highlighting selected row.

Regards,
Peter T

wrote in message
oups.com...
That would certainly work but I need to perform the function for many
rows and many columns, so I want some user friendly code that won't
require to much repetition, which is why I want a use an else
statement.

I bascially need some code so that when row 4 is selected, all text in
row 4 is made bold and red, while the text in ALL other rows is made
black and unbold. The, if row 7 is selected, all the text in row 7 is
made bold and red, while the text in ALL other rows is made black and
unbold.

Does anybody know how to perform this?