fillinspace
New member
- Joined
- Jan 12, 2016
- Messages
- 4
- Reaction score
- 0
- Points
- 0
Hi All Genius Excel Gurus,
I am using the below code to extract data from various spreadsheets in a folder.
The code is running absolutely fine but I also need to get the name of the file in one of the columns of the destinations file.
Is there a way we I can get the name of the files in each row copied from each file?
Thanks in advance,
I am using the below code to extract data from various spreadsheets in a folder.
The code is running absolutely fine but I also need to get the name of the file in one of the columns of the destinations file.
Code:
[COLOR=#333333]Sub Get_Info_By_Headers2()[/COLOR]
Dim sPath As String Dim sFil As String Dim owb As Workbook Dim twb As Workbook Dim ch Dim j As Long, a As Long, lr As Long With Application .Calculation = xlCalculationManual .EnableEvents = False .ScreenUpdating = False End With ch = Array("po number", "part number", "status", "quantity") Set twb = ThisWorkbook sPath = "C:\Users\dipak\Desktop\CRASH REPORT\" sFil = Dir(sPath & "*.xl*") Do While sFil <> "" And sFil <> twb.Name Set owb = Workbooks.Open(sPath & sFil) With owb.Sheets("data") lr = twb.Sheets("report").Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row + 1 For j = LBound(ch) To UBound(ch) a = .Rows(1).Find(ch(j), , , 1).Column .Range(.Cells(2, a), .Cells(.Cells(.Rows.Count, a).End(xlUp).Row, a)).Copy twb.Sheets("report").Cells(lr, j + 1) Next j End With owb.Close False 'Close no save sFil = Dir Loop With Application .Calculation = xlAutomatic .EnableEvents = True .ScreenUpdating = True End With [COLOR=#333333]End Sub[/COLOR]
Is there a way we I can get the name of the files in each row copied from each file?
Thanks in advance,