+ Reply to Thread
Results 1 to 3 of 3

Coping a Worksheet - but Getting an Error

  1. #1
    Max
    Guest

    Coping a Worksheet - but Getting an Error

    I'm trying to use the following code to select a worksheet from one opened
    file to another(filename 'fName' is passed to the sub function):


    FileList = Application _
    .GetOpenFilename( _
    FilterIndex:=1, _
    Title:="Open File That Contains Anderson
    List")




    Workbooks.Open Filename:=FileList
    Sheets("Anderson List").Select
    ActiveSheet.Copy After:=Workbooks(fName).Sheets
    End Sub

    But I'm getting a subscript out of range error. Any ideas why?

    --
    Thanks!
    Max

  2. #2
    PCLIVE
    Guest

    Re: Coping a Worksheet - but Getting an Error

    It seems that you're missing the sheet of which the copy should be placed
    after. However, that causes a different error. Make sure the fName is set
    appropriately. After you get the error, hover your mouse pointer over fName
    and see if it displays the correct file name. Also, make sure that file is
    open.

    Good Luck,
    Paul

    "Max" <[email protected]> wrote in message
    news:[email protected]...
    > I'm trying to use the following code to select a worksheet from one opened
    > file to another(filename 'fName' is passed to the sub function):
    >
    >
    > FileList = Application _
    > .GetOpenFilename( _
    > FilterIndex:=1, _
    > Title:="Open File That Contains
    > Anderson
    > List")
    >
    >
    >
    >
    > Workbooks.Open Filename:=FileList
    > Sheets("Anderson List").Select
    > ActiveSheet.Copy After:=Workbooks(fName).Sheets
    > End Sub
    >
    > But I'm getting a subscript out of range error. Any ideas why?
    >
    > --
    > Thanks!
    > Max




  3. #3
    GB
    Guest

    Re: Coping a Worksheet - but Getting an Error

    I would also recommend testing to see if the worksheet "Anderson List" exists
    before trying to select it.

    Not sure what is included in fName, if it is a full path and not just the
    name of the file, that may be an issue, also the fact that .xls is on the end
    of the filename may be a problem if it is there?

    Just an idea....


    "PCLIVE" wrote:

    > It seems that you're missing the sheet of which the copy should be placed
    > after. However, that causes a different error. Make sure the fName is set
    > appropriately. After you get the error, hover your mouse pointer over fName
    > and see if it displays the correct file name. Also, make sure that file is
    > open.
    >
    > Good Luck,
    > Paul
    >
    > "Max" <[email protected]> wrote in message
    > news:[email protected]...
    > > I'm trying to use the following code to select a worksheet from one opened
    > > file to another(filename 'fName' is passed to the sub function):
    > >
    > >
    > > FileList = Application _
    > > .GetOpenFilename( _
    > > FilterIndex:=1, _
    > > Title:="Open File That Contains
    > > Anderson
    > > List")
    > >
    > >
    > >
    > >
    > > Workbooks.Open Filename:=FileList
    > > Sheets("Anderson List").Select
    > > ActiveSheet.Copy After:=Workbooks(fName).Sheets
    > > End Sub
    > >
    > > But I'm getting a subscript out of range error. Any ideas why?
    > >
    > > --
    > > Thanks!
    > > Max

    >
    >
    >


+ 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