Select method of Range Class failed

E

Eric @ BP-EVV

What's wrong with the following statement that would cause the error: Select
method of Range Class failed ??

Worksheets("working data").Range("A" & rowx & ": K" & rowx).Select

Thanks !
 
J

Jim Thomlinson

You can only select a cell on an active worksheet. If the sheet is not active
then the code will crash... unless you use application.goto something like
this...

application.goto Worksheets("working data").Range("A" & rowx & ": K" & rowx)

or

with Worksheets("working data")
..select
..Range("A" & rowx & ": K" & rowx).Select
end with
 
J

JP

The obvious:

What is the value of rowx at the time this statement is executed? Also
what is rowx declared as?
Is there a worksheet named "working data"?

--JP
 
J

John Bundy

Not sure what you mean by "You can only select a cell on an active worksheet.
If the sheet is not active then the code will crash" Jim. I can get data from
any sheet i want, active or not without a select. As long as you include the
sheet name or index.
 
J

Jim Thomlinson

Yes you can get the value of the cell but you can not select the cell. The
select method of a range fails if the worksheet that the range is on is not
the active sheet. Run this code on a new worksbook

sub test
sheets("Sheet2").select
sheets("Sheet2").range("C3").select
msgbox "OK to here... but get ready to crash"
sheets("Sheet1").range("C3").select
end sub
 
J

John Bundy

I gotcha, i guess i didn't look close enough to see actually selecting the
cells, too long at work i guess!
 
E

Eric @ BP-EVV

Thanks to the three of you for some interesting banter....I got the issue
resolved....perhaps it was that rowx wasn't being properly set as JP implied,
perhaps it was something else....I hate to say I don't recall what I did to
fix it but it works good now. (Too much time at work for me too !)
 
J

JP

If there is a way you can execute your code without doing any
"selecting", it would make the code faster and less error prone.

--JP
 

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