+ Reply to Thread
Results 1 to 8 of 8

Copying Data from a variable-named workbook

  1. #1
    Registered User
    Join Date
    07-16-2012
    Location
    U.S
    MS-Off Ver
    Excel 2007
    Posts
    34

    Copying Data from a variable-named workbook

    Hello,


    I have a macro for an open spreadsheet that prompts a user to select certain other workbooks to open when the macro runs.
    The macro takes the selected file and writes the filepath in cell T1 of my main spreadsheet, then writes the actual workbook filename (the .csv part) in cell A4 and opens the selected file. At this point, I want the macro to take all the data from Sheet 1 of the selected file (located in A4) and copy it into Sheet 2 of the original workbook.

    Please keep in mind that the filepath/filename will always change depending on what the user chooses at the beginning, so I need the macro to be malleable enough to work with that. Essentially, I want my original workbook to open another workbook based off of the value of cell A4, then copy Sheet 1 from there and enter the values on sheet 2 of my original workbook. I want my main workbook's Sheet 2 to be the same as Sheet 1 of the selected file (file based off value in A4).

    Any help would be appreciated, thank you guys for indirectly answering SO many of my excel questions in the past.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copying Data from a variable-named workbook

    Try something like this...

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 07-16-2012 at 03:40 PM.

  3. #3
    Registered User
    Join Date
    07-16-2012
    Location
    U.S
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Copying Data from a variable-named workbook

    Thanks, the code works until it gets to the 'Copy sheet to ThisWorkbook' section. Once that section of code is read, I get "Run-time error '1004': Application-defined or object-defined error."
    It could definitely be an error on my end though, any trouble-shooting suggestions?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copying Data from a variable-named workbook

    Did you make any changes to the code I posted?

    Did the selected file actually open as a workbook? You should see it open.

  5. #5
    Registered User
    Join Date
    07-16-2012
    Location
    U.S
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Copying Data from a variable-named workbook

    I tried it with no changes, and with some changes and still run into the same error. With no changes made, the selected file will open successfully, but will produce the error message afterward (the file stays opened, it just doesn't copy the sheet). HOWEVER, the code works perfectly with a .xls file, just not with a .csv file. What section do I need to change to have it work with a .csv file?

  6. #6
    Registered User
    Join Date
    07-16-2012
    Location
    U.S
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Copying Data from a variable-named workbook

    Whoops, just realized the issue. The Main workbook is .xls and the ones I'm trying to import are .csv Any ideas on how to convert the .csv to .xls when it copies over? Sorry about not realizing that, and thank you for your patience and help

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copying Data from a variable-named workbook

    It worked for me but I'm using Excel 2003.

    Try this different method.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 07-16-2012 at 05:05 PM.

  8. #8
    Registered User
    Join Date
    07-16-2012
    Location
    U.S
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Copying Data from a variable-named workbook

    PERFECT, Thanks again!!

+ 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