LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Endless looping with Worksheet_change event (XL2003)

I have a data validation list on Sheet1. I have code that needs to trigger
each time that cell selection is changed. No problem so far.

When the value changes, I use that value to find corresponding records on
sheet3, and copy them into Sheet1 in the desired columns.

The base code seems to run pretty fast (when I run with breakpoints), but
when I run the whole thing, the machine locks up and I get an 'out of memory'
error. Is suspect it is because each time I paste in a cell value, this same
sub (worksheet_change) is retriggered. Is there a way to temporarily block
worksheet_change from even being triggered until my sub is complete?

Thank you,
Keith

Private Sub Worksheet_Change(ByVal Target As Range)

Application.Calculation = xlCalculationManual

If Target.Rows.Count = 1 And Target.Columns.Count = 1 Then
If Target = Sheet1.Range("F1") Then
SelectedOwner = Target.Value

LastSourceRow = lastRow(Sheet3) 'separate function, returns 397
PasteRow = 6

For I = 2 To LastSourceRow '397
If Sheet3.Range("AF" & I).Value = SelectedOwner Then
PasteRow = PasteRow + 1
Sheet1.Range("A" & PasteRow).Value = Sheet3.Range("A" &
I).Value
Sheet1.Range("B" & PasteRow).Value = Sheet3.Range("X" &
I).Value
Sheet1.Range("C" & PasteRow).Value = Sheet3.Range("Y" &
I).Value
Sheet1.Range("D" & PasteRow).Value = Sheet3.Range("Z" &
I).Value
Sheet1.Range("E" & PasteRow).Value = Sheet3.Range("AA" &
I).Value
Sheet1.Range("F" & PasteRow).Value = Sheet3.Range("U" &
I).Value
Sheet1.Range("G" & PasteRow).Value = Sheet3.Range("B" &
I).Value
Sheet1.Range("H" & PasteRow).Value = Sheet3.Range("C" &
I).Value
Sheet1.Range("I" & PasteRow).Value = Sheet3.Range("E" &
I).Value
Sheet1.Range("J" & PasteRow).Value = Sheet3.Range("F" &
I).Value
Sheet1.Range("K" & PasteRow).Value = Sheet3.Range("G" &
I).Value
Sheet1.Range("P" & PasteRow).Value = Sheet3.Range("N" &
I).Value
Sheet1.Range("Q" & PasteRow).Value = Sheet3.Range("O" &
I).Value
Sheet1.Range("R" & PasteRow).Value = Sheet3.Range("P" &
I).Value
Sheet1.Range("S" & PasteRow).Value = Sheet3.Range("J" &
I).Value
Sheet1.Range("T" & PasteRow).Value = Sheet3.Range("H" &
I).Value
End If
Next
Application.Calculation = xlCalculationAutomatic
End If
End If

End Sub



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet_Change Event Alectrical Excel Programming 5 September 4th 09 02:54 PM
Worksheet_change event eggpap[_2_] Excel Programming 8 January 25th 09 09:45 PM
Worksheet_Change event Sandy Excel Programming 3 August 4th 07 12:23 PM
How do I change a Worksheet_change event to a beforesave event? Tueanker Excel Programming 5 June 29th 07 03:00 PM
Change Event Endless loop :-( [email protected] Excel Programming 3 December 3rd 05 10:43 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"