Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 262
Default Code is not running

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Code is not running

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" wrote in message
...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Code is not running

Hi Keith,

A typo crept in!

Applicatiion.EnableEvents:=True


should read:

Application.EnableEvents:=True


---
Regards,
Norman


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Code is not running

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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Code is not running

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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 262
Default Code is not running

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
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
how to prevent code running when in a worksheet code Corey Excel Programming 5 August 13th 06 08:52 AM
Automatically running code Richard Excel Worksheet Functions 1 February 7th 06 09:35 PM
Running Code from Add-Ins DeanO Excel Programming 1 October 27th 05 05:20 PM
running code mark New Users to Excel 3 March 14th 05 09:14 AM
running VB code Cath[_3_] Excel Programming 1 November 21st 03 05:09 PM


All times are GMT +1. The time now is 07:08 AM.

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

About Us

"It's about Microsoft Excel"