View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Can't select worksheet

When you do not explicitly specify sheets you leave things to chance and
prone to errors as code is modified... Try this

with Worksheets("Sheet1")
.Unprotect
.Activate
.Cells(3, 1).Copy
.Cells(I, 1).Copy
end with

Code in standard code modules refer to the active sheet unless otherwise
specified. Code in sheets refer to the sheet they are in unless otherwise
specified. That being said ALWAYS explictly reference the sheets you are
working with. It makes your code more readable and much less prone to run
time error.
--
HTH...

Jim Thomlinson


"bw" wrote:

The following code is called from Sheet2:

1. Worksheets("Sheet1").Unprotect
2. Worksheets("Sheet1").Activate
3. Cells(3, 1).Copy 'THIS CELL IS COPIED FROM SHEET2....and is WRONG
4. Worksheets("Sheet1").Cells(I, 1).Copy 'THIS CELL IS COPIED FROM
SHEET1....and is CORRECT

Why doesn't line 3 do the copy from Sheet1 as I had intended?

Thanks,
Bernie