Unwanted 'loop' in Worksheet change?

WatfordKev

Board Regular
Joined
Mar 30, 2011
Messages
78
the following works perfectly for me

Private Sub Worksheet_Change(ByVal Target As Range)

' dynamic update of status :: Q1

If Range("D80").Value >= Range("C69") Then
Range("E80").Interior.ColorIndex = 4
Range("E80").Value = "Green "
ElseIf Range("D80").Value > Range("D69") And Range("D80").Value < Range("C69") Then
Range("E80").Interior.ColorIndex = 6
Range("E80").Value = "Amber "
If Range("D80").Value >= Range("B69") And Range("E80").Value = "Amber " Then
Range("E80").Interior.ColorIndex = 4
Range("E80").Value = "Green "
End If
ElseIf Range("D80").Value <= Range("D69") Then
Range("E80").Interior.ColorIndex = 3
Range("E80").Value = "Red "
End If


End Sub

However, the following does not - it appears to loop round and round and round!! All I have done (!) is add the lines in green, which does the same operation on the next rows on the worksheet! All I want is for the test to be run on the respective rows each time the worksheet gets changed!

Private Sub Worksheet_Change(ByVal Target As Range)

' dynamic update of status :: Q1

If Range("D80").Value >= Range("C69") Then
Range("E80").Interior.ColorIndex = 4
Range("E80").Value = "Green "
ElseIf Range("D80").Value > Range("D69") And Range("D80").Value < Range("C69") Then
Range("E80").Interior.ColorIndex = 6
Range("E80").Value = "Amber "
If Range("D80").Value >= Range("B69") And Range("E80").Value = "Amber " Then
Range("E80").Interior.ColorIndex = 4
Range("E80").Value = "Green "
End If
ElseIf Range("D80").Value <= Range("D69") Then
Range("E80").Interior.ColorIndex = 3
Range("E80").Value = "Red "
End If


' dynamic update of status :: Q2

If Range("D81").Value >= Range("C70") Then
Range("E81").Interior.ColorIndex = 4
Range("E81").Value = "Green "
ElseIf Range("D81").Value > Range("D70") And Range("D81").Value < Range("C70") Then
Range("E81").Interior.ColorIndex = 6
Range("E81").Value = "Amber "
If Range("D81").Value >= Range("B70") And Range("E81").Value = "Amber " Then
Range("E81").Interior.ColorIndex = 4
Range("E81").Value = "Green "
End If
ElseIf Range("D81").Value <= Range("D70") Then
Range("E81").Interior.ColorIndex = 3
Range("E81").Value = "Red "
End If


End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Put this at the beginning of your procedure:

Application.EnableEvents = False

and set it back to True at the end.
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top