+ Reply to Thread
Results 1 to 12 of 12

Import data from another workbook

  1. #1
    Registered User
    Join Date
    04-03-2005
    Posts
    2

    Import data from another workbook

    I need to import data in a daily basis from a workbook (b) to update my database in my workbook (a).

    So i need to make a macro that copies data from the other workbook (b) to to the workbook (a), in the way that it will be paste to the end of workbook in order to perserve the historical data i already got in workbook (a).

    Thanks in advance
    Busca

  2. #2
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    You should try the macro recorder that would write code similar to:
    Windows("Book2").Activate
    ActiveCell.FormulaR1C1 = "=[Test1.xls]Sheet1!R8C4"
    Best regards,

    Ray

  3. #3
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    Suppose you wish to copy data from WorkBook("Bank").Sheets("Sheet2") to WorkBook("House").Sheets("Sheet1") which already stores some data:


    Sub FromBankToHouse()
    Dim WS1 As WorkSheet, WS2 As WorkSheet

    Set WS1 =WorkBook("Bank").Sheets("Sheet2")
    Set WS2 =WorkBook("House").Sheets("Sheet1")

    WS1.UsedRange.Copy WS2.Cells.(Rows.Count, "A").end(xlUp)

    End Sub

    The code will copy from BANK and append new data onto existing data in HOUSE. That should get you going. Note that, using this basic structure, you can very easily loop through several Workbooks and/or Worksheets in the copying process...but remember to specify the appropriate range in place of USEDRANGE.
    Last edited by Myles; 09-21-2006 at 01:56 PM.
    HTH
    Myles

    ...constantly looking for the smoother pebble while the whole ocean of truth lies before me.

  4. #4
    Registered User
    Join Date
    04-03-2005
    Posts
    2
    Thanks for your replies but im nocive at VBA.

    I atteched a file with an exemple with i want to do.

    In sheet1 a got my daily data. I want to copy it to sheet2 in order to perserve the old data i already got in it.

    Thanks Very Much
    Busca
    Attached Files Attached Files
    Last edited by Busca; 09-21-2006 at 01:45 PM.

  5. #5
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    Busca,
    If you want to copy from Sheet1 to Sheet2, use:


    HTML Code: 

    Copy the above code and paste it in a general module in the VB Editor. Run it.
    Last edited by Myles; 09-21-2006 at 01:58 PM.

  6. #6
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    Attachment supplied:


    HTML Code: 

  7. #7
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    Attachment supplied:


    HTML Code: 

  8. #8
    Registered User
    Join Date
    12-28-2006
    Posts
    97

    Re: Import data from another workbook

    This is exactly what I need to do as well, with one catch. The workbook I import from has a name that is constantly changing. I have one work book where Nurses in the field fill out the information and then I import that info into a master spreadsheet. The nurses in the field save the workbook as the patient name. Is there a way to create this macro when the file name changes?

  9. #9
    Registered User
    Join Date
    08-08-2011
    Location
    mysore, India
    MS-Off Ver
    Excel 97
    Posts
    3

    Smile Re: Import data from another workbook

    sir,

    i am using 5 excel workbooks to make a consolidate report
    1 workbook for consolidate report
    2 to 4 workbooks for concern branch report

    my question is when i update 2 to 4 workbooks 1st workbook should get updated, how to do this

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,618

    Re: Import data from another workbook

    1. The forum rules (#4) require that you ask for help in the forums provided and not in the member's visitor message box nor in the member's private message box.
    2. You must also ALWAYS start your own thread (rule #2). Do not resurrect threads that are several years old (either to ask a question or offer a solution that's no longer needed.
    3. Posted code must always be wrapped with code tags (rule #3).
    Ben Van Johnson

  11. #11
    Registered User
    Join Date
    09-28-2011
    Location
    Nevada
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Import data from another workbook

    Quote Originally Posted by insanity66 View Post
    This is exactly what I need to do as well, with one catch. The workbook I import from has a name that is constantly changing. I have one work book where Nurses in the field fill out the information and then I import that info into a master spreadsheet. The nurses in the field save the workbook as the patient name. Is there a way to create this macro when the file name changes?
    I need to do the same thing. Did you ever figure out how to do this?

  12. #12
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,618

    Re: Import data from another workbook

    @shofer:
    Again??
    1. The forum rules (#4) require that you ask for help in the forums provided and not in the member's visitor message box nor in the member's private message box.
    2. You must also ALWAYS start your own thread (rule #2). Do not resurrect threads that are several years old (either to ask a question or offer a solution that's no longer needed.

+ 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