# VBA Script  - Copy all the data from one workbook  to another workbook



## fahadalambd (Dec 20, 2022)

Good Afternoon everyone, 

I need to copy all the data from one workbook (*Test1.xlsx*) to another workbook (*Test2.xlsm*).
There are so many sheets in *Test1.xlsx *file but I need to copy only "Sheet1".
So far, I tried the below code but it is not working 


```
Sub move_data()
    Workbooks("Test1.xlsx").Worksheets("Sheet1").Range("A1").Copy _
    Workbooks("Test2.xlsm").Worksheets("Sheet2").Range("A2")
End Sub
```

Please help me if you know the solution. 
Thanks in advance


----------



## jolivanes (Dec 20, 2022)

```
.Range("A1").Copy
```
That only copies cell A1.


----------



## jolivanes (Dec 20, 2022)

Both workbooks need to be open.
Code can be run from either workbook.
Change references to meaninful names and change as required.

```
Sub Maybe()
Dim wb1 As Workbook, wb2 As Workbook
Dim sh1 As Worksheet, sh2 As Worksheet

Set wb1 = Workbooks("Book11111.xlsm")    '<----- Workbook is open. Change name as required.
Set wb2 = Workbooks("Book22222.xlsm")    '<----- Workbook is open. Change name as required.

Set sh1 = wb1.Sheets("Sheet1")    '<---- Change reference as required
Set sh2 = wb2.Sheets("Sheet1")    '<---- Change reference as required

Application.ScreenUpdating = False

sh1.Cells(1, 1).Resize(sh1.Cells(Rows.Count, 1).End(xlUp).Row, sh1.UsedRange.Columns.Count).Copy sh2.Cells(2, 1)    '<---- Pastes in A2 on down/right

Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
```


----------



## fahadalambd (Dec 20, 2022)

jolivanes said:


> Both workbooks need to be open.
> Code can be run from either workbook.
> Change references to meaninful names and change as required.
> 
> ...


Thank you so much mate. This code is working perfectly


----------



## jolivanes (Dec 20, 2022)

Thank you for letting us know and enjoy the upcoming festive holidays.


----------

