ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet_Change or Worksheet_SelectionChange (https://www.excelbanter.com/excel-programming/341170-worksheet_change-worksheet_selectionchange.html)

Bret

Worksheet_Change or Worksheet_SelectionChange
 
How do I keep Worksheet_Change from getting caught in a loop.

I use this Worksheet Event for a User to enter their ID in a Cell, the
program actually queries a database and returns records that fill into 4
other cells. When I debug the code I notice it gets caught in a loop.
When the records fill into the 4 cells, the Worksheet_Change is triggered
and it goes round and round. How do I stop this? I get the same problem
with Worksheet_SelectionChange. Please help. Much thanks.



Rowan[_9_]

Worksheet_Change or Worksheet_SelectionChange
 
Disable events while your code is running eg

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False

'do whatever

ErrorHandler:
Application.EnableEvents = True
End Sub

Hope this helps
Rowan

Bret wrote:
How do I keep Worksheet_Change from getting caught in a loop.

I use this Worksheet Event for a User to enter their ID in a Cell, the
program actually queries a database and returns records that fill into 4
other cells. When I debug the code I notice it gets caught in a loop.
When the records fill into the 4 cells, the Worksheet_Change is triggered
and it goes round and round. How do I stop this? I get the same problem
with Worksheet_SelectionChange. Please help. Much thanks.



Tom Ogilvy

Worksheet_Change or Worksheet_SelectionChange
 
Application.EnableEvents = False

code to enter data

Application.EnableEvents = True

--
Regards,
Tom Ogilvy

"Bret" wrote in message
...
How do I keep Worksheet_Change from getting caught in a loop.

I use this Worksheet Event for a User to enter their ID in a Cell, the
program actually queries a database and returns records that fill into 4
other cells. When I debug the code I notice it gets caught in a loop.
When the records fill into the 4 cells, the Worksheet_Change is triggered
and it goes round and round. How do I stop this? I get the same problem
with Worksheet_SelectionChange. Please help. Much thanks.






All times are GMT +1. The time now is 12:27 PM.

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