My code is very slow (10 + min for each sheet) due to the amount of data that I have. I believe that there may be a way to speed up its use of arrays, but I'm not sure how to do this. I will try to explain the situation in detail.
I have two worksheets with invoices # s, part # s and selling prices (among other information), which I am trying to compare to find the differences. I created a unique number for each row of data using the concatenation of invoice # and part # on both sheets. I also sorted both sheets manually by this number. I would like to find which of these unique # s are on sheet1 and not on sheet2 and vice versa. (Another part of this is to check those that match each other and see if the selling price is different, but I think I could figure it out quite easily.) The goal is to see which invoices were skipped. either partially or fully by the supplier and my company.
I have about 10 thousand rows of data in one sheet and 11k in another. Below is the code I am currenlty, which was changed from what I found at www.vb-helper.com/howto_excel_compare_lists.html, and looked at answers to similar questions on this site. There is an almost identical second submaterial with inverted sheets. I do not know if it is possible to write only one that does this in both directions.
Private Sub cmdCompare2to1_Click()
Dim first_index As Integer
Dim last_index As Integer
Dim sheet1 As Worksheet
Dim sheet2 As Worksheet
Dim r1 As Integer
Dim r2 As Integer
Dim found As Boolean
Set sheet1 = Worksheets(1)
Set sheet2 = Worksheets(2)
Application.ScreenUpdating = False
first_index = 1
last_index = sheet1.Range("a" & Rows.Count).End(xlUp).Row
' For each entry in the second worksheet, see if it's
' in the first.
For r2 = first_index To last_index
found = False
' See if the r1-th entry on sheet 2 is in the sheet
' 1 list.
For r1 = first_index To last_index
If sheet1.Cells(r1, 16) = sheet2.Cells(r2, 9) Then
' We found a match.
found = True
Exit For
End If
Next r1
' See if we found it.
If Not found Then
' Flag this cell.
sheet2.Cells(r2, 9).Interior.ColorIndex = 35
End If
Next r2
Application.ScreenUpdating = True
End Sub
It works great for small data sets, but with a lot of lines that I go through, it just takes forever, and not one of the accountants wants to use it. Ideally, instead of just turning the differences into green, they copied them onto a separate sheet, i.e. Sheet 3 would have everything on sheet 2, not sheet 1, but I will take what I can get at that moment.
, , , . , . , , , , ?