Run-Time Error 1004, Debugging

  • Thread starter Thread starter I Maycotte
  • Start date Start date
I

I Maycotte

Hi everyone,

I keep getting the runtime error on the following piece of code.

"Run-Time Error 1004: Select Method of Range class Failed"


Code
-------------------
ActiveWorkbook.Worksheets("Sheet2").Range("C12:H32").Select
Selection.ClearContents

ActiveWorkbook.Worksheets("Sheet1").Select
Selection.ClearContent
-------------------


Can anybody help me with this? I don't know what's wrong.

Thanks,

Isaa
 
Hi Isaac,

Try:

With ActiveWorkbook
.Worksheets("Sheet2").Range("C12:H32").ClearContents
.Worksheets("Sheet1").Select
Selection.ClearContents
End With
 
You can not select a cell on a sheet that is not the active sheet. As luck
would have it you rarely need to select cells. give this a try...

ActiveWorkbook.Worksheets("Sheet2").Range("C12:H32").ClearContents
ActiveWorkbook.Worksheets("Sheet1").Cells.ClearContents
 
Thanks Norman. That works. But isn't that essentially what I had?
What was wrong? Do you know
 
Oh. So, if I wanted to do what I originally had as code, I would hav
had to Activate and deactive each sheet separately
 
Hi Isaac,
Oh. So, if I wanted to do what I originally had as code, I would have
had to Activate and deactive each sheet separately?

Yes, but as Jim correctly indicated, selections are rarely necessary or
desirable.
 
Yup... this would have worked...

ActiveWorkbook.Worksheets("Sheet2").Select
Range("C12:H32").Select
Selection.ClearContents

ActiveWorkbook.Worksheets("Sheet1").Select
Selection.ClearContents
 
Back
Top