Run-Time Error 1004, Debugging

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
 
N

Norman Jones

Hi Isaac,

Try:

With ActiveWorkbook
.Worksheets("Sheet2").Range("C12:H32").ClearContents
.Worksheets("Sheet1").Select
Selection.ClearContents
End With
 
G

Guest

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
 
I

I Maycotte

Thanks Norman. That works. But isn't that essentially what I had?
What was wrong? Do you know
 
I

I Maycotte

Oh. So, if I wanted to do what I originally had as code, I would hav
had to Activate and deactive each sheet separately
 
N

Norman Jones

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.
 
G

Guest

Yup... this would have worked...

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top