Hi, i have this code below and every time i make a change to the worksheet, Excel crashes. Whats the problem?
![]()
Please Login or Register to view this content.
Hi, i have this code below and every time i make a change to the worksheet, Excel crashes. Whats the problem?
![]()
Please Login or Register to view this content.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Lastrow = Worksheets("Edit").Cells(Worksheets("Edit").Rows.Count, "A").End(xlUp).Row
SEQ = 1
For I = 2 To Lastrow
If Cells(I, 6).Value = "GOOD" Or Cells(I, 6).Value = "BAD" Then
Cells(I, 7).Value = SEQ
SEQ = SEQ + 1
Else: Cells(I, 7).Value = ""
End If
Next I
Application.EnableEvents = True
End Sub
EXPLAINATION:
each of your changes in the loop triggered the Worksheet_change Event ... you need to turn this off before changing fields and then turn on again after e.g. Application.EnableEvents
Last edited by nimrod; 05-25-2016 at 07:05 PM.
A) because you are making changes to the worksheet within the Worksheet Change event handler, B) because you are not restricting the cells you monitor and C) you're looping through all the used cells in a column and changing them.
Use Application.EnableEvents = False before changes and True afterwards.
Trevor Shuttleworth - Retired Excel/VBA Consultant
I dream of a better world where chickens can cross the road without having their motives questioned
'Being unapologetic means never having to say you're sorry' John Cooper Clarke
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks