Sheets().Range().Select

b9k9uk

New Member
Joined
Jul 31, 2016
Messages
37
Hi

Using the above notation:

Sheets(x).Range(xx).select produce a run time error 1004 select method of range class failed.

I have a VBA taking data from sheets(x).range(x) and placing it in sheets(y).range(y)

What should be the correct notation for this simple task?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Are you trying to select a cell on a sheet that isn't the ActiveSheet? If yes tell us what you are trying to do after the select as you rarely need to select a cell to work with it or preferably post your full code as you have it.
 
Last edited:
Upvote 0
Are you trying to select a cell on a sheet that isn't the ActiveSheet? If yes tell us what you are trying to do after the select as you rarely need to select a cell to work with it or preferably post your full code as you have it.

This is the code:

Sheets("G2G").Select

WeekNumber = Sheets("G2G").Range("B3").Value
'
' Start If - Then until WeekNumber becomes greater than 9
'
If WeekNumber = 1 Then
'
' Click_Week1 Macro
'
Sheets("G2GDATA").Range("Z3:AF14").Select
Selection.Copy
Sheets("G2G").Range("C4").Select
ActiveSheet.Paste
 
Upvote 0
Try the code below...

Code:
Sub testit1()
WeekNumber = Sheets("G2G").Range("B3").Value
If WeekNumber = 1 Then Sheets("G2GDATA").Range("Z3:AF14").Copy Sheets("G2G").Range("C4")
End Sub
 
Upvote 0
Sorry, it doesn't work. Should there be a .Paste at the end of the line?

In the mean time what I have got to work is..

Sheets("G2GDATA").Select
Range("AG3:AM14").Select
Selection.Copy
Sheets("G2G").Select
Range("C4").Select
ActiveSheet.Paste

which seems like a lot of code but it works.

Many thanks for your help.
 
Upvote 0
Last edited:
Upvote 0
Hi Mark,

If the OP has Option Explicit set at the top of the module then the code will definitely fail - based on what has been provided that's the only obvious potential point of failure.

Hi B9k9UK,

What error message do you get when you try Marks code?
 
Upvote 0
He hasn't mentioned having Option Explicit at the top of his code and it is not in the code he/she posted and no variables are declared in the code he/she posted.
If it is then he needs

Code:
Sub testit1()
Dim WeekNumber As Long
WeekNumber = Sheets("G2G").Range("B3").Value
If WeekNumber = 1 Then Sheets("G2GDATA").Range("Z3:AF14").Copy Sheets("G2G").Range("C4")
End Sub

Depending as stated on whether he/she adjusted the range and if he/she is still doing the test.
 
Last edited:
Upvote 0
Hi Mark,

If the OP has Option Explicit set at the top of the module then the code will definitely fail - based on what has been provided that's the only obvious potential point of failure.

Hi B9k9UK,

What error message do you get when you try Marks code?

Oops my bad!

Yes Marks code does work. I had the data in C4. When I deleted the data and then ran Marks code it did work.

My bad, it does work, many many thanks.

PS I do not have Option Explicit. That is a bit beyond me at the moment! I am using a series of Sub routines (Sub XXXX () - End Sub). Small steps maekth progress until we can run :)
 
Last edited:
Upvote 0
Oops my bad!

Yes Marks code does work. I had the data in C4. When I deleted the data and then ran Marks code it did work.

My bad, it does work, many many thanks.

Thanks for the feedback and happy you got it working :biggrin:
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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