+ Reply to Thread
Results 1 to 14 of 14

Macro to import data from one workbook into another & saving

  1. #1
    Forum Contributor
    Join Date
    02-15-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    100

    Macro to import data from one workbook into another & saving

    Hi,

    I'm hoping this will be a fairly simple one. I've got a spreadsheet listing applications on PCs (assets), one line per application, and need to import that info into another document for each PC and save it with a file name which = the PC name (asset number). I've attached a couple of sample files to try to explain what i mean.

    For asset number PC037014 I need the corresponding fields filled and the list of applications pasted under where is says Additional Software List (inserting more rows if there are too many applications to fit in). Once the information has been populated, i'd like the file to be saved in a specific folder then move onto the next asset number in the list.

    I hope that makes sense.

    Any help would be hugely appreciated
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to import data from one workbook into another & saving

    Hi Bad boy,

    Name your data sheet as "Data" and your build sheet as "Template" keep them open and try this:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    02-15-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    100

    Re: Macro to import data from one workbook into another & saving

    That's amazing, thank you so much!!

    I wonder if you might be able to help me with one other issue?

    Is there any way to make the macro only create build sheets for results of a filter. For example, if i only want to create build sheets for people with cost centre 15150, i would like to be able to filter on 15150 and run the macro.

    Does that make sense?

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to import data from one workbook into another & saving

    Hi Bad boy,

    Thanks for the rep! - I used a temporary book and an array and I didn't code for the autofilter - so, if you manually filter your data:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    02-15-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    100

    Re: Macro to import data from one workbook into another & saving

    Thank you for your reply. I've tried using the code though and it doesn't seem to work. I get a type mismatch error at : CC = AF(i, 6)

    Any ideas?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to import data from one workbook into another & saving

    HI Bad boy,

    You could try changing:

    Please Login or Register  to view this content.
    to:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-15-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    100

    Re: Macro to import data from one workbook into another & saving

    Hmm, when I do that I get "Compile Error: Expected array" at the AF part of CN = AF(i, 2)

    This is the code I'm currently using. I made a few little tweaks like changing sheet names and defining the group so the sheets can be saved into specific folders depending on their group. I just can't get it to work with filters.

    Please Login or Register  to view this content.
    Last edited by badlydrunkboy; 07-09-2014 at 06:26 AM.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to import data from one workbook into another & saving

    Why did you insert the "With" block:
    Please Login or Register  to view this content.
    The array AF must be declared as a variant, so change:

    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.
    Last edited by xladept; 07-09-2014 at 03:35 PM.

  9. #9
    Forum Contributor
    Join Date
    02-15-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    100

    Re: Macro to import data from one workbook into another & saving

    Sorry, I think that must have been my mistake in not removing the With block. I have removed it now and also changed the AF to be declared as a variant but the code is still failing with a subscript out of range error at ": LOC = AF(i, 11) & " " & AF(i, 12)"

    Please Login or Register  to view this content.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to import data from one workbook into another & saving

    Hi Bad boy,

    Have you a different sample? My sample data sheet has only ten columns

  11. #11
    Forum Contributor
    Join Date
    02-15-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    100

    Re: Macro to import data from one workbook into another & saving

    Of course. Here you go.
    Attached Files Attached Files

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to import data from one workbook into another & saving

    Hi Bad Boy,

    I used "Build Sheet" re "Template" and I made the column limit variable:

    Please Login or Register  to view this content.
    Last edited by xladept; 07-11-2014 at 01:10 PM.

  13. #13
    Forum Contributor
    Join Date
    02-15-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    100

    Re: Macro to import data from one workbook into another & saving

    This is perfect. Thank you so much!

  14. #14
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to import data from one workbook into another & saving

    You're welcome and thanks for the rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How do I import data from spreadsheet to macro enabled workbook on seperate spreadsheets ?
    By vyokus in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-03-2014, 06:53 PM
  2. VBA Macro code - import data from another workbook (VLOOKUP)
    By madi1004 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-17-2013, 03:27 PM
  3. Import "|" delimitted files into workbook - Saving that workbook (determine path)
    By schmidt1962 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2013, 11:28 AM
  4. Macro to Import Data from Closed Workbook to CSV File
    By groundin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2013, 09:39 PM
  5. Renaming Active.Workbook and saving it without saving Macro
    By Djwill in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-04-2012, 03:09 AM

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