irishr_ram
New Member
- Joined
- Jul 16, 2013
- Messages
- 10
Hi All,
I have a requirement to extract several rows from different spreadsheet files.
I can with the below code extract a row from each as it just loops through the files but cannot figure how to get it to loop through each spreadsheet on the required tab until the end of the rows and then move onto the next file. Also once I get it to do that I want to be able to incorporate that each set of rows from each sheet is pasted below each other combined.
Any help appreciated
I have a requirement to extract several rows from different spreadsheet files.
I can with the below code extract a row from each as it just loops through the files but cannot figure how to get it to loop through each spreadsheet on the required tab until the end of the rows and then move onto the next file. Also once I get it to do that I want to be able to incorporate that each set of rows from each sheet is pasted below each other combined.
Any help appreciated
Code:
rowTarget = 3
rowSource = 5
Set wsCostCentreView = Sheets("Cost Centre View")
Folderpath = "C:\Users\fxd38\Desktop\Data"
Filename = Dir(Folderpath & "*.xls*")
Do While Filename <> ""
'open the source file and set the source worksheet
Set wbSource = Workbooks.Open(Folderpath & Filename, ReadOnly:=True, UpdateLinks:=False)
On Error Resume Next
Set wsForecastHourly = wbSource.Worksheets("Forecast - Hourly")
Set wsForecastAC = wbSource.Worksheets("Forecast - Additional Costs")
Set wsInfo = wbSource.Worksheets("Info")
Application.StatusBar = "Updating" & " " & wsInfo.Range("B2").Value & " " & "Financials"
'wsForecastHourly.Range("B5", Range("B" & row.Count).End(xlUp)).Copy
'wsCostCentreView.Range("C3").End(xlUp)(2).PasteSpecial xlPasteValues
wsCostCentreView.Range("C" & rowTarget).Value = wsForecastHourly.Range("B" & rowSource).Value
wsCostCentreView.Range("D" & rowTarget).Value = wsForecastHourly.Range("C" & rowSource).Value
'wsCostCentreView.Range("E" & rowTarget).Value = wsForecastAC.Range("A4").Value
wsCostCentreView.Range("F" & rowTarget).Value = wsForecastHourly.Range("A" & rowSource).Value
'wsCostCentreView.Range("G" & rowTarget).Value = wsForecastAC.Range("B4").Value
wsCostCentreView.Range("H" & rowTarget).Value = wsForecastHourly.Range("D" & rowSource).Value
'ActiveCell.Offset(1, 0).Select
'row = row + 1
'close the source workbook, increment the output row and get the next file
wbSource.Close SaveChanges:=False
rowTarget = rowTarget + 1
rowSource = rowSource + 1
Filename = Dir()
Loop
Last edited by a moderator: