Hello,
I am using the following code to pull data from multiple spreadsheets in a directory tree in to one master sheet called "Results.xlsx"
I would like to modify the code to only pull data from Row 3+ (until a blank row is encountered) of every sheet that contains data except the 1st sheet which has a common name in all sheets.
The code in its current form:
I'm familiar with VBA in Access, but it seems that Excel is it's very own beast.
Thanks for the help
I am using the following code to pull data from multiple spreadsheets in a directory tree in to one master sheet called "Results.xlsx"
I would like to modify the code to only pull data from Row 3+ (until a blank row is encountered) of every sheet that contains data except the 1st sheet which has a common name in all sheets.
The code in its current form:
Code:
Private Sub commandButton1_Click()
strPathSrc = "S:\Programs\IND\IND EOI Applications\Internal Review Meetings Summary\2016" ' Source files folder
strMaskSrc = "*.xlsx" ' Source files filter mask
isheetsrc = 2 ' Source sheet index or name
strPathDst = "C:\test\Results\Results.xlsx" ' Destination file
iSheetDst = 1 ' Destination sheet index or name
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkBookDst = objExcel.Workbooks.Open(strPathDst)
Set objSheetDst = objWorkBookDst.Sheets(iSheetDst)
Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.Namespace(strPathSrc)
Set objItems = objFolder.Items()
objItems.Filter 64 + 128, strMaskSrc
objExcel.DisplayAlerts = False
For Each objItem In objItems
Set objWorkBookSrc = objExcel.Workbooks.Open(objItem.Path)
Set objSheetSrc = objWorkBookSrc.Sheets(isheetsrc)
GetUsedRange(objSheetSrc).Copy
Set objUsedRangeDst = GetUsedRange(objSheetDst)
iRowsCount = objUsedRangeDst.Rows.Count
objWorkBookDst.Activate
objSheetDst.Cells(iRowsCount + 1, 1).Select
objSheetDst.Paste
objWorkBookDst.Application.CutCopyMode = False
objWorkBookSrc.Close
Next
End Sub
Function GetUsedRange(objSheet)
With objSheet
Set GetUsedRange = .Range(.Cells(1, 1), .Cells(.UsedRange.Row + .UsedRange.Rows.Count - 1, .UsedRange.Column + .UsedRange.Columns.Count - 1))
End With
End Function
I'm familiar with VBA in Access, but it seems that Excel is it's very own beast.
Thanks for the help