Avoid re-running code in Worksheet_SelectionChange

L

L Mehl

Hello --

Today I am more logic- and VBA-challenged than usual.

In a workbook, a user can change a cell value by:
1 - double-click a cell to toggle between Y and N
or
2 - enter "Y" or "N" (ignore trapping for lower-case entries)

After such a change, I want to run AutoFilter code after such a change in
cell value; this updates another range in same worksheet

Problem:
Running AutoFilter code ([a] below) re-triggers Worksheet_SelectionChange

How can I prevent re-running code in Worksheet_SelectionChange the second
time?

Reading this group, it sounds like I should involve
Application.EnableEvents=False
my code...
Application.EnableEvents=True

If this is the solution, can someone tell me where to place the "False" and
"True"? Do they belong at and [c]?

Also, can someone point me to code that returns the user to the cell that
was originally clicked?


Here is the code I am using:

Worksheet_BeforeDoubleClick
'handles user double-clicking in a cell to toggle between "Y" and "N"
If Not Intersect(Target, Me.Range("basic_yn")) Is Nothing Then
Cancel = True
If Target.Value = "Y" Then
Me.Range(Target.Address).Value = "N"
Else
Me.Range(Target.Address).Value = "Y"
End If
'_SelectionChange handles running filters after double-click to toggle
values
'Call Filter_1
'Call Filter_2
End If


Worksheet_SelectionChange
'if change a value in column range "basic_yn" re-filter the table
'handles user entering Y or N (ignore trapping for lower-case entries)
If Not Intersect(Target, Me.Range("basic_yn")) Is Nothing Then
'[a] run autofilters (these trigger further changes in the sheet)
'don't run these again if they have already been run once because of a
change in a cell

Call Filter_1
Call Filter_2
'return to cell clicked
Cells.Range(strNameCellClicked).Select
[c]
End If


Thanks in advance for any help.

Larry Mehl
 

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