# Microsoft Office Application Help - Excel Help forum > Excel Programming / VBA / Macros >  >  Import data from another workbook

## Busca

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

----------


## raypayette

You should try the macro recorder that would write code similar to:
Windows("Book2").Activate
ActiveCell.FormulaR1C1 = "=[Test1.xls]Sheet1!R8C4"

----------


## Myles

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.

----------


## Busca

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

----------


## Myles

Busca,
If you want to copy from Sheet1 to Sheet2, use:





```

```



Copy the above code and paste it in a general module in the VB Editor. Run it.

----------


## Myles

Attachment supplied:





```

```

----------


## Myles

Attachment supplied:





```

```

----------


## insanity66

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?

----------


## pdjchamarajanagar

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

----------


## protonLeah

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*).

----------


## shofer

> 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?

----------


## protonLeah

@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.

----------

