View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
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.