+ Reply to Thread
Results 1 to 2 of 2

[SOLVED] MACRO not working on two different files

  1. #1
    Marco
    Guest

    [SOLVED] MACRO not working on two different files

    I have the code below on my PERSONAL workbook and works fine. When I try to
    copy it to another workbook, it doesn't get past the first RANGE line. The
    error I get is "Select Method of Range class Failed."

    Why would this happen?

    Thanks.


    Company = InputBox("For which Company is this TB for?", "Company Code",
    "112, 115, 127, 176, 177")
    ChDir "C:\Documents and Settings\marco.rodas\Desktop"
    Workbooks.OpenText Filename:= _
    "C:\Documents and Settings\marco.rodas\Desktop\Trial Balance
    TEMP.txt", Origin:= _
    xlWindows, StartRow:=1, DataType:=xlFixedWidth,
    FieldInfo:=Array(Array(0, _
    1), Array(1, 1), Array(13, 1), Array(34, 1), Array(75, 1), Array(94,
    1), Array(113, 1))
    Range("B11:G20192").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=3, Criteria1:="=" & Company & "*",
    Operator:=xlAnd
    Selection.Copy


  2. #2
    Jim Thomlinson
    Guest

    RE: MACRO not working on two different files

    Try adding activesheet just ahead of the range statements...

    Activesheet.Range("B11:G20192").Select
    Activesheet.Range(Selection, Selection.End(xlDown)).Select

    --
    HTH...

    Jim Thomlinson


    "Marco" wrote:

    > I have the code below on my PERSONAL workbook and works fine. When I try to
    > copy it to another workbook, it doesn't get past the first RANGE line. The
    > error I get is "Select Method of Range class Failed."
    >
    > Why would this happen?
    >
    > Thanks.
    >
    >
    > Company = InputBox("For which Company is this TB for?", "Company Code",
    > "112, 115, 127, 176, 177")
    > ChDir "C:\Documents and Settings\marco.rodas\Desktop"
    > Workbooks.OpenText Filename:= _
    > "C:\Documents and Settings\marco.rodas\Desktop\Trial Balance
    > TEMP.txt", Origin:= _
    > xlWindows, StartRow:=1, DataType:=xlFixedWidth,
    > FieldInfo:=Array(Array(0, _
    > 1), Array(1, 1), Array(13, 1), Array(34, 1), Array(75, 1), Array(94,
    > 1), Array(113, 1))
    > Range("B11:G20192").Select
    > Range(Selection, Selection.End(xlDown)).Select
    > Selection.AutoFilter
    > Selection.AutoFilter Field:=3, Criteria1:="=" & Company & "*",
    > Operator:=xlAnd
    > Selection.Copy
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1