PC Review


Reply
Thread Tools Rate Thread

Code is not running

 
 
=?Utf-8?B?S2VpdGg=?=
Guest
Posts: n/a
 
      6th Nov 2006
I have a lot of code in Sheet 1, and at all works fine. However I need Sheet
2 to be the same. I copied sheet 1 to sheet 2, then I copied the code for
the worksheet change event from sheet 1 to sheet, but the code isn't running.

Why is this? The code does not referr to a sheet name. In fact I made the
first line of the code

debug.print "Got this far"

But even this simple line dosn't execute. What have I hone wrong?

I selected worksheet and the change event from the top of the code window, I
didn't copy that over from Sheet 1 in case that made any difference.
 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      6th Nov 2006
Hi Keith,

One possibility is that Events have been inadvertently disabled.

In the immediate window (Ctrl-G), try:

Applicatiion.EnableEvents:=True

and hit the enter key.


If this does not resolve your problem, post the problematic code.


---
Regards,
Norman



"Keith" <(E-Mail Removed)> wrote in message
news:17CCFEA4-DB95-4C8A-8A5B-(E-Mail Removed)...
>I have a lot of code in Sheet 1, and at all works fine. However I need
>Sheet
> 2 to be the same. I copied sheet 1 to sheet 2, then I copied the code for
> the worksheet change event from sheet 1 to sheet, but the code isn't
> running.
>
> Why is this? The code does not referr to a sheet name. In fact I made
> the
> first line of the code
>
> debug.print "Got this far"
>
> But even this simple line dosn't execute. What have I hone wrong?
>
> I selected worksheet and the change event from the top of the code window,
> I
> didn't copy that over from Sheet 1 in case that made any difference.



 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      6th Nov 2006
Hi Keith,

A typo crept in!

> Applicatiion.EnableEvents:=True


should read:

Application.EnableEvents:=True


---
Regards,
Norman


 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      6th Nov 2006
Kieth, I helps those who want to help you if you would post the code that
causes the problem. Then they don't have to guess about what you are trying
to describe.

"Keith" wrote:

> I have a lot of code in Sheet 1, and at all works fine. However I need Sheet
> 2 to be the same. I copied sheet 1 to sheet 2, then I copied the code for
> the worksheet change event from sheet 1 to sheet, but the code isn't running.
>
> Why is this? The code does not referr to a sheet name. In fact I made the
> first line of the code
>
> debug.print "Got this far"
>
> But even this simple line dosn't execute. What have I hone wrong?
>
> I selected worksheet and the change event from the top of the code window, I
> didn't copy that over from Sheet 1 in case that made any difference.

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      6th Nov 2006
Just some added information:

If you copied the sheet (and not just the data on the sheet), the event code
would be copied as well. Perhaps you should try this for similar situations
in the future.

to refer to the sheet containing the code, use the ME qualifier rather than
explicitely using the sheet name. This would make you code a bit more
robust.

When referring to the sheet with the code, Rather than

set rng = sheet1.Range("A1")
or
set rng = Worksheets("Sheet1").Range("A1")

use
set rng = me.Range("A1")

as an example.
--
Regards,
Tom Ogilvy


"Keith" wrote:

> I have a lot of code in Sheet 1, and at all works fine. However I need Sheet
> 2 to be the same. I copied sheet 1 to sheet 2, then I copied the code for
> the worksheet change event from sheet 1 to sheet, but the code isn't running.
>
> Why is this? The code does not referr to a sheet name. In fact I made the
> first line of the code
>
> debug.print "Got this far"
>
> But even this simple line dosn't execute. What have I hone wrong?
>
> I selected worksheet and the change event from the top of the code window, I
> didn't copy that over from Sheet 1 in case that made any difference.

 
Reply With Quote
 
=?Utf-8?B?S2VpdGg=?=
Guest
Posts: n/a
 
      6th Nov 2006
Thanks to everyone for their help and sugestions. After looking at the first
response from Norman I noticed that the original code was no longer working
either.

Using Me is a good idea but in this case it would not have helped since I
was using ActiveSheet in my code and not a sheet name.

I have started again from the point where the original sheet is working
again and instead of copying everything I copied the code only then in sheet
2 allowed Excel to create the subroutine header and end sub and simply pasted
the code in-between.

This worked fine.

Once again thanks for all your help.

Keith


"Tom Ogilvy" wrote:

> Just some added information:
>
> If you copied the sheet (and not just the data on the sheet), the event code
> would be copied as well. Perhaps you should try this for similar situations
> in the future.
>
> to refer to the sheet containing the code, use the ME qualifier rather than
> explicitely using the sheet name. This would make you code a bit more
> robust.
>
> When referring to the sheet with the code, Rather than
>
> set rng = sheet1.Range("A1")
> or
> set rng = Worksheets("Sheet1").Range("A1")
>
> use
> set rng = me.Range("A1")
>
> as an example.
> --
> Regards,
> Tom Ogilvy
>
>
> "Keith" wrote:
>
> > I have a lot of code in Sheet 1, and at all works fine. However I need Sheet
> > 2 to be the same. I copied sheet 1 to sheet 2, then I copied the code for
> > the worksheet change event from sheet 1 to sheet, but the code isn't running.
> >
> > Why is this? The code does not referr to a sheet name. In fact I made the
> > first line of the code
> >
> > debug.print "Got this far"
> >
> > But even this simple line dosn't execute. What have I hone wrong?
> >
> > I selected worksheet and the change event from the top of the code window, I
> > didn't copy that over from Sheet 1 in case that made any difference.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Suspend old code while new code is running Shawn Microsoft Excel Programming 1 21st Jan 2010 03:09 PM
while my c# code running ,clicks on excel document interrupts code Kayıhan Microsoft Excel Programming 2 8th Apr 2009 11:54 AM
How can I update VBA code in a module that is running my VBA code? Gummy Microsoft Excel Programming 3 12th Jun 2007 06:26 PM
how to prevent code running when in a worksheet code Corey Microsoft Excel Programming 5 13th Aug 2006 08:52 AM
Running code when viewing aspx code =?Utf-8?B?TWF0dGhpYXMgSC4=?= Microsoft ASP .NET 2 11th Feb 2005 02:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:16 AM.