Your code is very inefficient as it is written forever. You did not specify specifically how many lines are in your “global” and “detailed” sheets (you mentioned 800, not sure if both). But if there were 1000 in each of them, your two loops are 1000x1000 = 1 million cycles.
The best solution is not to use VBA in general, but to use the VLOOKUP function in Excel. Here is what you need to do:
Sorting the information sheet by column A Then in the global sheet, in cell O3, you put the following formula: = VLOOKUP (A3, Details! $ A2: $ I (regardless of the last row), 3, FALSE)
If you are not familiar with this function, it takes the first argument, looks at it in the first column of the second argument until it finds a match, and then returns the value in that row in the third argument column. The last “FALSE” only gives you an exact match, otherwise you will get #NA (if you use TRUE, you will get the closest match).
Then copy this formula all over the sheet.
Then copy the column and paste the values. This eliminates the forum and simply leaves the values, which makes everything much faster.
Then sort the table by this column, and all #NA will fall together, and you can delete it all in one operation.
If you want to do this through VBA, the steps described above can be easily encoded:
Private Sub btnVlookUp_Click() Dim i, j, lastG, lastD As Long Dim DetailsTable as Range ' find last row lastG = Sheets("Global").Cells(Rows.Count, "B").End(xlUp).Row lastD = Sheets("Details").Cells(Rows.Count, "A").End(xlUp).Row ' Make sure this is sorted. If not, you'll need to add a sort command Set DetailsTable=Sheets("Details").Range(Sheets("Details").Cells(1, 2), Sheets.Cells(lastD, 9)) Sheets("Global").Range("O3")="=VLOOKUP(A3," & DetailsTable.address(external:=true) & "3,FALSE)" Sheets("Global").Range("O3").copy destination:=Sheets("Global").Range( Sheets("Global").cells(3,"O"),Sheets("Global").cells(lastG,"O")) End Sub
This is the beginning, but you need to go. Good luck