Range Select not working?!

dowingc

Board Regular
Joined
Oct 27, 2002
Messages
77
I have a very simple spreadsheet that is copying cell values from one workbook to another. At the start of the code I am trying to setup the initial activecell locations by using this code. however, it keeps erroring out but I don't know why. Help greatly appreciated! I am running this on Office XP, but it may run on O2K in the future....

Option Explicit
Public Sub macro1_Click()
Dim delay As Integer
Dim symbol, t As String
ChDir "c:\stock"
Sheets(1).Select
Range("A2").Select
Sheets(2).Select
Range("A2").Select <---------here is where i get the error "Selection method of Range class failed"
....


Thanks!

Chris
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Is A2 on sheet2 protected? Are there any objects on sheet2 that are active when you switch to it, i.e., if you look at sheet2, is there a chart that is active?
 
Upvote 0
Try this. I think your references might be the issue. This code should fix up any problems.

Option Explicit
Public Sub macro1_Click()
Dim WS1 as worksheet, WS2 as worksheet
Dim delay As Integer
Dim symbol, t As String
ChDir "c:\stock"

Sheets(1).activate
set WS1 =Activesheet
WS1.Range("A2").Select

Sheets(2).Activate
Set ws2= Activesheet
WS2.Range("A2").Select
 
Upvote 0
Not that I am aware of. I just put some labels (just text) on the top at A1:L1, thus having A2 be the first blank cell. I looked for protection and can't see any. It is obviously something with sheet2 though, I removed the line of code causing problems and another .select on sheet2 errored....frustrating...

Just read the post with code and testing it, seems to be working, thanks!!!

Chris
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,850
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top