Error on select statement

G

Guest

I am working in Excel 97 and am getting a 1004 error - Application defined or
object defined error. The code is

Worksheets(strWrkSht).Range(Cells(2, 2), Cells(intCopyTo1,
intCopyTo)).Select

I have stepped through the code to determine the value of the variables:

intCopyTo1=211
intCopyTo = 6
strWrkSht=Master

All variables are accurate. Any help would be appreciated.
 
G

Guest

I get this same error message if I try to run the macro while the active
worksheet is other than Master ( I think the select method only works on the
active workbook).
 
D

Dave Peterson

You can only select a range if its worksheet is active/selected.

so one way...

with worksheets(strWrkSht)
.select
.range(.cells(2,2),.cells(intCopyTo1,intCopyTo)).select
end with

But maybe you could just do what ever you had to do to that range without
selecting it:

with worksheets(strWrkSht)
'.select
.range(.cells(2,2),.cells(intCopyTo1,intCopyTo)).clearcontents
end with


Note the additional dots in front of the .cells(). This means that this object
belongs to the object in the previous With statement.
 

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