View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Help with events

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

' Auto Data update macro

On Error Resume Next


Application.EnableEvents = False

If Target.Column = 12 Then

ThisRow = Target.Row

If (CLng(Target.Value) - CLng(Cells(1, 3))) = 15 Then

With Rows([ThisRow]).Interior
.ColorIndex = 4
.Pattern = xlSolid
End With

ElseIf (CLng(Target.Value) - CLng(Cells(1, 3))) = 8 Then

With Rows([ThisRow]).Interior
.ColorIndex = 46
.Pattern = xlSolid
End With

ElseIf (CLng(Target.Value) - CLng(Cells(1, 3))) = 1 Then

Rows([ThisRow]).Interior
.ColorIndex = 3
.Pattern = xlSolid
End With

ElseIf CLng(Target.Value) = 0 Then

Rows([ThisRow]).Interior
.ColorIndex = 0
.Pattern = xlSolid
End With

Else

Rows([ThisRow]).Interior
.ColorIndex = 1
.Pattern = xlSolid
End With


End If

Application.EnableEvents = True
end sub

--
Regards,
Tom Ogilvy

"A1pro" wrote:

I 've got this macro (code below) that automatically does colours the row
when you type something on column 12.

I want it to be able to modify column 12 and then for all the colouring to
take place. At the moment it will not let me add anything. It will simply
select the row and colour it.

Any ideas how to do this, i.e. add data and then have the macro colour the
row?

TIA



Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

' Auto Data update macro

On Error Resume Next


Application.EnableEvents = False

If Target.Column = 12 Then

ThisRow = Target.Row

If (CLng(Target.Value) - CLng(Cells(1, 3))) = 15 Then

Rows([ThisRow]).Select
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
End With

ElseIf (CLng(Target.Value) - CLng(Cells(1, 3))) = 8 Then

Rows([ThisRow]).Select
With Selection.Interior
.ColorIndex = 46
.Pattern = xlSolid
End With

ElseIf (CLng(Target.Value) - CLng(Cells(1, 3))) = 1 Then

Rows([ThisRow]).Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With

ElseIf CLng(Target.Value) = 0 Then

Rows([ThisRow]).Select
With Selection.Interior
.ColorIndex = 0
.Pattern = xlSolid
End With

Else

Rows([ThisRow]).Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
End With


End If

Application.EnableEvents = True
end sub