I need help to put these codes together and possibly expand. The first piece of code I found online and it should loop through my folder that stores hundreds of workbooks. Once file is opened it should loop through each worksheet in each workbook and look for columns labeled “ItemID” and “XItemID”. Number of worksheets varies and could count from 1 to let’s say 10 or even more. Once column is found the whole content of the column should be copied to NewWorkbook which would store all values found from all files. If there are any blank cells or #N/A found it should be ignored. The second piece of code should look for these columns. To summarize, I need to extract these values from each of these columns and paste them into NewWorkbook, column A. I hope my explanation was precise. Thanks in advance for your help.
Sub MyLoops()
'DECLARE AND SET VARIABLES
Dim wbk As Workbook
Dim Filename As String
Dim Path As String
Path = "C:\Documents\Desktop\MyFiles\" 'CHANGE PATH
Filename = Dir(Path & "*.xlsx")
'OPEN EXCEL FILES
Do While Len(Filename) > 0 'IF NEXT FILE EXISTS THEN
Set wbk = Workbooks.Open(Path & Filename)
wbk.Close True
Filename = Dir
Loop
End Sub
Dim LastColumn1 As Long
Dim LastRow1 As Long
Dim LastRow2 As Long
Dim FindMatch1 As Range
Dim FindMatch2 As Range
LastColumn1 = Cells(1, Columns.Count).End(xlToLeft).Column 'Finds last column in worksheet
Set FindMatch1 = Range(Cells(1, 1), Cells(1, LastColumn)).Find(What:="ItemID", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False) 'Finds position of ItemID column in worksheet
LastRow1 = Cells(Rows.Count, FindMatch1).End(xlUp).Row
Set FindMatch2 = Range(Cells(1, 1), Cells(1, LastColumn)).Find(What:="XItemID", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False) 'Finds position of XItemID column in worksheet
LastRow2 = Cells(Rows.Count, FindMatch2).End(xlUp).Row