Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Avoid re-running code in Worksheet_SelectionChange

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 [b] 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
[b]
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


---

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.797 / Virus Database: 541 - Release Date: 11/15/2004


Reply
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
Where?Worksheet code module or Worksheet_SelectionChange event han Kenzie Excel Worksheet Functions 4 January 30th 06 09:41 PM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
Worksheet_SelectionChange code: lavish use of system resources? [email protected] Excel Discussion (Misc queries) 4 December 1st 05 03:39 AM
Adding Worksheet_SelectionChange code by macro Alan Webb[_5_] Excel Programming 2 May 19th 04 10:25 PM
Insert code into each worksheet's "Sub Worksheet_SelectionChange" Function John[_46_] Excel Programming 2 September 23rd 03 04:11 AM


All times are GMT +1. The time now is 11:23 AM.

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

About Us

"It's about Microsoft Excel"