2 Replies - 4209 Views - Last Post: 26 January 2011 - 07:18 AM Rate Topic: ****- 1 Votes

#1 meatloaf  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 65
  • Joined: 05-September 07

VB6 Run-time error '1004': Select method of Range class failed

Posted 25 January 2011 - 09:12 AM

Hello-here is an excerpt of the code that is giving me problems:

Sub SL2Result()
' Filter Beta worksheet and copy to RESULT worksheet
    Sheets("Beta").Range("$A:$G").AutoFilter Field:=1, Criteria1:="~*"
    Sheets("Beta").Range("$A:$G").AutoFilter Field:=7, Criteria1:="=*ST*" _
        , Operator:=xlOr, Criteria2:="=*SL*"
    Sheets("Beta").AutoFilter.Range.Copy Destination:=Sheets("RESULT").Range("A1")
    Sheets("Beta").AutoFilterMode = False

' Copy Beta titles to worksheet RESULT
    Sheets("Beta").Rows("19:19").Copy Destination:=Sheets("RESULT").Range("A1")
    
' Add 3 new columns G H I 
    Sheets("RESULT").Columns("G:G").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.Insert Shift:=xlToLeft, CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.Insert Shift:=xlToLeft, CopyOrigin:=xlFormatFromLeftOrAbove

' . . .
End Sub 'SL2Result


I get this error:

Quote

Run-time error 1004: Select method of Range class failed

for this line of code:
    Sheets("RESULT").Columns("G:G").Select

I don't understand what is wrong with this!

Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: VB6 Run-time error '1004': Select method of Range class failed

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 386
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: VB6 Run-time error '1004': Select method of Range class failed

Posted 25 January 2011 - 03:57 PM

It seems you cannot select a range on an inactive sheet.
Sheets("RESULT").Activate
Sheets("RESULT").Columns("G:G").Select


Was This Post Helpful? 1
  • +
  • -

#3 meatloaf  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 65
  • Joined: 05-September 07

Re: VB6 Run-time error '1004': Select method of Range class failed

Posted 26 January 2011 - 07:18 AM

That worked - thank you!
I don't understand why it didn't work in the first place; I use that type of code all the time and has worked fine. o well..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1