Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Worksheet Change Event problem

6 views
Skip to first unread message

Doug

unread,
Mar 8, 2004, 1:34:15 PM3/8/04
to
I have the following code on Sheet1: Thanks to Frank K.
--------------
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit
Sub
On Error GoTo CleanUp:
With Target
If .value then
Application.EnableEvents = False
Call DoSomething 'Private Sub on same sheet
end if
End With

CleanUp:
Application.EnableEvents = True
End Sub

-------------

Change Event fires but evaluates "A1" to be "Nothing" and
exits. But if I simply click the formula for "A1" and
hit ENTER it works just fine!

What am I doing wrong?

Tom Ogilvy

unread,
Mar 8, 2004, 1:49:40 PM3/8/04
to
Clicking a cell does not fire the change event. Editing a cell does (which
you do by clicking in the formula and hiting enter). I suspect you are
mistaken that this fires when you click in a cell.

--
Regards,
Tom Ogilvy

"Doug" <anon...@discussions.microsoft.com> wrote in message
news:8f4f01c4053b$f5bcb190$a301...@phx.gbl...

Doug

unread,
Mar 8, 2004, 2:08:37 PM3/8/04
to
Tom,

You are correct -- clicking in a cell does nothing. What
I tried to say is that despite that the contents of A1
are clearly non-blank and the change event code gets
called, it evaluates the contents as blank unless, as you
pointed out, I touch the formula and hit enter.

Doug

>.
>

Tom Ogilvy

unread,
Mar 8, 2004, 2:19:34 PM3/8/04
to
the code never looks at the contents of Cell A1. It is set up to not do
anything unless the cell edited is A1. That is what this line does:

If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit


This basically says "is the cell triggering the change event cell A1?"

If it is not, then exit this subroutine (do nothing).

--
Regards,
Tom Ogilvy

"Doug" <anon...@discussions.microsoft.com> wrote in message

news:63e201c40540$c2913ac0$a601...@phx.gbl...

Bob Phillips

unread,
Mar 8, 2004, 2:51:58 PM3/8/04
to
Doug,

Unless something is changed, that code won't even be entered. The nothing
does not refer to the contents of A1, but the fact of whether the object
resulting from a union of A1 and the changed cell is nothing or not.

Even if A1 is not empty and you change B1, the code will check whether it is
A1 that was change at that time, conclude not, and exit.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Doug" <anon...@discussions.microsoft.com> wrote in message

news:63e201c40540$c2913ac0$a601...@phx.gbl...

anon...@discussions.microsoft.com

unread,
Mar 8, 2004, 4:51:29 PM3/8/04
to
Thanks for the response Bob.

I've scattered several message boxes in that code and,
when A1 has indeed changed, it enters the change event
where it is always evaluated at Nothing. A1 is a logical
determined by the contents of a list-box -- YES or NO.

In testing all this I'm calculating the value of A1 by
the contents of the list-box making A1 either True or
False.

I'm lost.

"With Target" segment where it errors out

>.
>

Bob Phillips

unread,
Mar 8, 2004, 5:35:41 PM3/8/04
to
Send me your workbook, and I will look at it for you.

bob . phillips @ tiscali . co . uk - remove the spaces

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

<anon...@discussions.microsoft.com> wrote in message
news:915001c40557$8377b2d0$a001...@phx.gbl...

0 new messages