range.select error??

aceee

Board Regular
Joined
Feb 21, 2008
Messages
239
hey all

I have this:

Code:
Private Sub CommandButton1_Click()
Worksheets("Sheet1").Activate
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate
ActiveCell.PasteSpecial
End Sub

it errors to: SELECT METHOD OR RANGE CLASS FAILED

any idea?
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,151
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
If your code is in a worksheet module (which I suspect it is), then Range("A1") defaults to a reference to the sheet containing the code, which you can't select because it is no longer active. You need to qualify the range with the sheet:
Code:
Private Sub CommandButton1_Click()
Worksheets("Sheet1").Activate
Worksheets("Sheet1").Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate
ActiveCell.PasteSpecial
End Sub
or even:
Code:
Private Sub CommandButton1_Click()
Worksheets("Sheet1").Range("A1").End(xlDown).Offset(1,0).PasteSpecial
End Sub
 

aceee

Board Regular
Joined
Feb 21, 2008
Messages
239
Worksheets("Sheet1").Range("A5:K299").Select
select method from class range failed???
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995

ADVERTISEMENT

You need to select parent object first.
Code:
With Sheets("sheet1")
    .Select
    .Range("a5:k299").Select
End With
BTW why are you selecting the range ?
 

aceee

Board Regular
Joined
Feb 21, 2008
Messages
239
thanks..
selecting a range, to copy and paste special into another sheet
 

aceee

Board Regular
Joined
Feb 21, 2008
Messages
239

ADVERTISEMENT

don't understand why sometimes these things work.. and sometimes not.. now i get another error
Code:
With Sheets("sheet1")
    .Select
    .Range("a5:k299").Select
End With
Sheets("Sheet2").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

range of method failed on the pastspecial command...
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
No need to "Select/Activate"
Code:
Sheets("sheet1").Range("a5:k299").Copy
Sheets("Sheet2").Range("a1").PasteSpecial xlPasteValues
 

Watch MrExcel Video

Forum statistics

Threads
1,123,322
Messages
5,600,951
Members
414,417
Latest member
Nobu

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
Top