ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet_SelectionChange (https://www.excelbanter.com/excel-programming/314587-worksheet_selectionchange.html)

mangesh_yadav[_143_]

Worksheet_SelectionChange
 

I have something like this on a larger scale:

5 cells: A1, B1 and B2, C1 and C2.

If I enter value in B1, B2 becomes 0. And vice-versa.
If I enter 0 in A1, then B1 and B2 becomes 0.
If C1 is 0 I cannot enter values in B1, and if C2 is 0 I cannot ente
value in B2.


The problem is, if I use Worksheet_Change event, then the event i
fired twice when I try to enter a value in B1 (whe C1 is 0), because
undo the action in this case, which fires the event on resetting B2.

If I use Worksheet_SelectionChange, then it works well as long as
press the ENTER button after entering a value, but if I use the arro
keys, then the whole logic goes for a toss.

Any better alternatives.....?

- Manges

--
mangesh_yada
-----------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...fo&userid=1047
View this thread: http://www.excelforum.com/showthread.php?threadid=27203


Frank Kabel

Worksheet_SelectionChange
 
Hi
use the worksheet_change event but before changing data in the sheet use the
statement
application.enableevents=false

And don't forget to enable them again at the end of your event procedure with
application.enableevents=true


"mangesh_yadav" wrote:


I have something like this on a larger scale:

5 cells: A1, B1 and B2, C1 and C2.

If I enter value in B1, B2 becomes 0. And vice-versa.
If I enter 0 in A1, then B1 and B2 becomes 0.
If C1 is 0 I cannot enter values in B1, and if C2 is 0 I cannot enter
value in B2.


The problem is, if I use Worksheet_Change event, then the event is
fired twice when I try to enter a value in B1 (whe C1 is 0), because I
undo the action in this case, which fires the event on resetting B2.

If I use Worksheet_SelectionChange, then it works well as long as I
press the ENTER button after entering a value, but if I use the arrow
keys, then the whole logic goes for a toss.

Any better alternatives.....?

- Mangesh


--
mangesh_yadav
------------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...o&userid=10470
View this thread: http://www.excelforum.com/showthread...hreadid=272030




All times are GMT +1. The time now is 06:52 AM.

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