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?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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
 
Upvote 0
Worksheets("Sheet1").Range("A5:K299").Select
select method from class range failed???
 
Upvote 0
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 ?
 
Upvote 0
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...
 
Upvote 0
No need to "Select/Activate"
Code:
Sheets("sheet1").Range("a5:k299").Copy
Sheets("Sheet2").Range("a1").PasteSpecial xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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