Format using VBA not activating when needed
You've got it working on the active cell and not the target cell, try this:-
Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("K:K")) Is Nothing Then Exit Sub
If Me.Cells(Target.Row, "K") = "" Then
With Target.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = xlNone
End With
End If
If Me.Cells(Target.Row, "K") = "AH" Then
With Target.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = 45
.Pattern = xlSolid
End With
End If
Mike
"RobN" wrote:
In the following procedure, how do I have the formatting occur as soon as
the operator exits the cell (either by the keyboard or mouse)? At the moment
this procedure requires the operator to exit and then activate that cell
again.
Rob
Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("K:K")) Is Nothing Then Exit Sub
If Me.Cells(Target.Row, "K") = "" Then
With ActiveCell.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = xlNone
End With
End If
If Me.Cells(Target.Row, "K") = "AH" Then
With ActiveCell.Offset(0, -10).Resize(1, 16).Interior
.ColorIndex = 45
.Pattern = xlSolid
End With
End If
End Sub
|