Pull data from sheet in another workbook.

Status
Not open for further replies.

NateD1

New Member
Joined
Apr 1, 2020
Messages
27
Office Version
  1. 365
Platform
  1. Windows
Hi All,
in need of some help,
i have the below code which works within a workbook to copy multiple sheets to one sheet, however i need to adapt this so it does the same but pulls the data from a closed work book and paste it into a sheet in my open workbook.

example: workbook1 (current open) > run macro > opens closed workbook2 via file path (the name of the file is the same, except date at end changes daily( WB2 19.11.2020) > runs below code in WB2 to combine sheets > paste data to WB1 sheet1.

if possible to have a variable where i can change the date in a cell in WB1 before running so that it looks at the correct file name.

VBA Code:
Sub CopyToMaster()

Application.ScreenUpdating = False

Dim i As Long
Dim Lastrow As Long
Dim ans As Long

For i = 3 To 7
With Sheets(i)
    ans = .Cells(Rows.Count, "A").End(xlUp).Row
    Lastrow = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row + 1
        .Cells(2, 1).Resize(ans, 7).Copy Sheets("Master").Cells(Lastrow, 1)
End With
Next
Application.ScreenUpdating = True
End Sub
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Status
Not open for further replies.

Watch MrExcel Video

Forum statistics

Threads
1,118,862
Messages
5,574,713
Members
412,613
Latest member
EFRATA
Top