View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Bill Oertell[_2_] Bill Oertell[_2_] is offline
external usenet poster
 
Posts: 18
Default Worksheet_SelectionChange

Yeah. I know. But at least you didn't append, "You idiot" at the end. Thanks.

BTW, I ran into this bit of code on MrExcel.com. It does the job nicely and
doesn't erase my existing conditional format:

Private Sub WorkSheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
If Target.Cells.Count = 1 Then
With Rows(Target.Row).Interior
.ColorIndex = 6
'.Pattern = xlSolid
End With
End If
End Sub

I changed it slightly to:

Private Sub WorkSheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count = 1 Then Exit Sub
Cells.Interior.ColorIndex = xlNone
With Rows(Target.Row).Interior
.ColorIndex = 6
End With
End Sub


"Bob Phillips" wrote in message
...
bit late, 17 hours after I answered it<vbg

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bill Oertell" wrote in message
...
I posted a question in this thread about how a certain line in this code

works,
and I would appreciate it if everyone would just ignore it. Pretend I

didn't
ask it. Thanks.

"Bob Phillips" wrote in message
...
That is clever.

It works because it sets up conditional formatting on the row, based

upon
whether the row is empty or not. By deleting the condition first then
re-creating it does ensure that the number of conditions on the sheet

are
minimised.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bill Oertell" wrote in message
...
Found this bit of code on a website. Can't remember where, but I can

find
out
if anyone's interested. The initial row does not remain highlighted.
Works
rather nicely. And it has the advantage of not highlighting the row

if
it's
empty.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim strRow As String
Cells.FormatConditions.Delete

With Target.EntireRow
strRow = .Address
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=COUNTA(" &

strRow
&
")0"
.FormatConditions(1).Interior.ColorIndex = 6
End With
End Sub

But I do have one question. How does the the line of code:
.FormatConditions.Add Type:=xlExpression, Formula1:="=COUNTA(" &

strRow &
")0"
prevent the sub from highlighting an empty row. I understand the

COUNTA
function, but I don't understand how that line prevents the following

line
from
executing.

Thanks.