Worksheet_Change or Worksheet_SelectionChange

G

Guest

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.
 
R

Rowan

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
 
T

Tom Ogilvy

Application.EnableEvents = False

code to enter data

Application.EnableEvents = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top