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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Osvaldo Palmeiro

Well-known Member
Joined
Feb 24, 2009
Messages
728
Office Version
  1. 365
Platform
  1. Windows
Hi.
Try activate the sheet before selecting the range, like this:
Code:
[B]Sheets("Flights").Activate
Range("Revenue").Select [/B]
 
Upvote 0

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
15,195
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
@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,195,624
Messages
6,010,750
Members
441,568
Latest member
abbyabby

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