Hello everyone
I got a master file containing numbers in column H.
See pictures
VLfTF4L.png
also I have got lots seperate files in a folder "C:\data\"
each of these files contains numbers in column H
File 1:
LSkuVP2.png
File2:
TuQ3ERP.png
Now I need to loop through all cells in column H in the master file, compare each cell in column H(master file) to the each of the each number in the column H in the seperate files.
If the number is the same copy the value in the seperate file from the column G same row; paste it in the column G in the master file in the same row as the first number but column G.
My problem is my loop is missing the last iteration I dont know why.
See my code below:
Sub test()
Dim wb As Workbook
Set Mwb = ActiveWorkbook
Dim folderPath As String
folderPath = "C:\DATA\"
Dim filename As String
filename = Dir(folderPath & "*.xlsx")
For i = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
MioNr = Cells(i, "H").Value
Set wb = Workbooks.Open(folderPath & filename)
wb.Activate
For x = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
CIonr = Cells(x, "H").Value
If CIonr = MioNr Then
Cells(x, "I").Copy
Mwb.Activate
Cells(i, "I").Activate
ActiveSheet.Paste
wb.Close
End If
Next x
Next i
End Sub
Could someone help me?
Thank you in advance
Bookmarks