ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SelectionChange (https://www.excelbanter.com/excel-programming/388666-selectionchange.html)

Alex McDermott

SelectionChange
 
Hi,

I have the following but for the code to work the user needs to goback to
the cell, if they type 100 and then goto another cell nothing happens but
then if revisit the cell it works - what am I doing wrong?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngActual As Range
Dim rngActualFinish As Range

Set rngActual = Range("Actual")
Set rngActualFinish = Range("ActualFinish")
ColumnID = Range("ActualFinish").Column

If Not Intersect(rngActual, Target) Is Nothing Then
With Cells(ActiveCell.Row, ColumnID)
If Cells(ActiveCell.Row, ColumnID) = "" Then
If ActiveCell.Value = 100 Then
.Interior.ColorIndex = 3
Else
.Interior.ColorIndex = 15
End If

End If
End With
End If
End Sub





Tom Ogilvy

SelectionChange
 
SelectionChange is fired when the cell is selected.

The Change event is fired when a change is made to a cell. Use the Change
event.

--
Regards,
Tom Ogilvy


"Alex McDermott" wrote:

Hi,

I have the following but for the code to work the user needs to goback to
the cell, if they type 100 and then goto another cell nothing happens but
then if revisit the cell it works - what am I doing wrong?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngActual As Range
Dim rngActualFinish As Range

Set rngActual = Range("Actual")
Set rngActualFinish = Range("ActualFinish")
ColumnID = Range("ActualFinish").Column

If Not Intersect(rngActual, Target) Is Nothing Then
With Cells(ActiveCell.Row, ColumnID)
If Cells(ActiveCell.Row, ColumnID) = "" Then
If ActiveCell.Value = 100 Then
.Interior.ColorIndex = 3
Else
.Interior.ColorIndex = 15
End If

End If
End With
End If
End Sub







All times are GMT +1. The time now is 11:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com