motabrasil
Member
Dear friends,
I have a macro that seems to work perfectly when testing. However it stuck when I move it to a real word (more than thousand row data). The purpose of this code is to compare to different sheets and make some calculation when the search match. The problem is each sheet has more than 10 thousand rows and I need to concatenate 4 columns to create a unique string to compare.
It seems that doing this I have more than 1 billion loops. My Question: What am I doing wrong here? How to have the same result using a faster way?
Thanks in advance
Mota
*****
[pre]
[/pre]
I have a macro that seems to work perfectly when testing. However it stuck when I move it to a real word (more than thousand row data). The purpose of this code is to compare to different sheets and make some calculation when the search match. The problem is each sheet has more than 10 thousand rows and I need to concatenate 4 columns to create a unique string to compare.
It seems that doing this I have more than 1 billion loops. My Question: What am I doing wrong here? How to have the same result using a faster way?
Thanks in advance
Mota
*****
[pre]
Code:
lRow = Sheet2.Range("A" & Rows.Count).End(xlUp).Row
nRow = Sheet1.Range("B" & Rows.Count).End(xlUp).Row
For n = 2 To nRow
For y = 1 To 4
Result1 = Result1 & Sheet1.Cells(n, y)
Next y
For i = 2 To lRow
For j = 1 To 4
Result2 = Result2 & Sheet2.Cells(i, j)
Next j
If Result1 = Result2 Then
Sheet1.Range("E" & n) = "Test"
Sheet1.Range("F" & n) = Sheet2.Range("E" & i) + 7
End If
Result2 = ""
Next i
Result1 = ""
Next n