VBA: Error 1004: Select Method of Range class failed

crowso

New Member
Joined
Jun 4, 2015
Messages
9
I'm writing some code to copy some information from one sheet to another and I know that without a worksheet reference <acronym title="visual basic for applications">VBA</acronym> will be looking at the range on what it regards as the active sheet.

However it says that it failed.

The code I'm trying to get it:

If Range("A2") > 0 Then
Sheets("Flights").Range("Revenue").Select <------ this is the bit which is failing!!
Selection.Copy
Sheets("Rows Linked to Flights").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
If Range("A2").Value = "" Then Range("B2") = ""
End If



Any help would be greatly appreciated!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi.
Try activate the sheet before selecting the range, like this:
Code:
[B]Sheets("Flights").Activate
Range("Revenue").Select [/B]
 
Upvote 0
@crowso, if you don't use select and selection then you don't need to Activate the sheet and the code will run a bit faster.

Rich (BB code):
    If Range("A2") > 0 Then
        Sheets("Flights").Range("Revenue").Copy
        Sheets("Rows Linked to Flights").Range("B2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                                                                                                           :=False, Transpose:=False
        If Range("A2").Value = "" Then Range("B2") = ""
    End If
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,607
Members
449,090
Latest member
vivek chauhan

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