I have been able to achieve this many different ways, but my methods become obsolete if there are too many rows.
My first attempt was something like this:
sub search()
Dim listVals as variant
Dim dataVals as variant
Dim i as long
Dim x as long
Dim list as worksheet
Dim data as worksheet
Dim results as range
Set list = Sheets("Sheet1")
Set data = Sheets("Sheet2")
Set results = Sheets("Sheet3").Range("A" & Sheets("Sheet3").Cells.SpecialCells(xlcellTypeLastCell).Row)
listVals = list.Range("A1:A" & Cells.SpecialCells(xlCellTypeLastCell).Row)
dataVals = data.Range("A1:A150000")
For i = ubound(listVals,1) to lbound(listVals,1) Step -1
For x = ubound(dataVals,1) to lbound(dataVals,1) Step -1
if listVals(i,1) = dataVals(x,1) then
nextRow = results + 1
list.range("A" & i & ":" & "G" & i).Copy Destination:= nextRow
data.range("A" & x & ":" & "G" & x).Copy Destination:= nextRow.Offset(0,7)
End if
Next
Next
End Sub
This worked fine for smaller groups of data, but with 150,000 rows, this code brings my computer to its knees. I also tried using .Find, and it got even slower.. My final attempts were with Scripting.Dictionary and FileSystemObject, seemed as if they would have worked much better, but I couldn't quite get either to work correctly.
So if anyone can code a search that can look through > 200,000 rows
-Find a match,
-Select the first blank row on Results Sheet,
-Return the entire row of corresponding data from sheet1,
-Skip a column, and continue adding the entire row of corresponding data from sheet2 (so that everything is on the same row)
-repeat for all occurrences of all strings in ColumnA of a list sheet
it would be greatly appreciated!
Bookmarks