Hello all,
I need help to improve the speed of this code (thanks Roxxien for the code)., I I got rows like 20000 the code takes very long to execute .
Please help!!
Kalle
'============================================
Private Sub CommandButton1_Click()
Dim rsheet1 As Range
Dim rsheet2 As Range
Dim bcolor As Boolean
'First loop to compare sheet1 to sheet2
bcolor = False
For Each rsheet1 In Intersect(Sheets("sheet1").UsedRange.Cells, Sheets("sheet1").Range("A:F"))
For Each rsheet2 In Intersect(Sheets("sheet2").UsedRange.Cells,
Sheets("sheet2").Range("A:F"))
If rsheet1 = rsheet2 Then
bcolor = True
GoTo finded1:
End If
Next
finded1:
'If we never finded him, we color
If bcolor = False Then
rsheet1.Interior.ColorIndex = 4
If (rsheet1.Column <> 1) Then
Sheets("sheet1").Cells(rsheet1.Row, 1).Interior.Color = vbYellow
End If
Else
'Reset for next cell to compare
bcolor = False
End If
Next
End Sub
'============================================
I need help to improve the speed of this code (thanks Roxxien for the code)., I I got rows like 20000 the code takes very long to execute .
Please help!!
Kalle
'============================================
Private Sub CommandButton1_Click()
Dim rsheet1 As Range
Dim rsheet2 As Range
Dim bcolor As Boolean
'First loop to compare sheet1 to sheet2
bcolor = False
For Each rsheet1 In Intersect(Sheets("sheet1").UsedRange.Cells, Sheets("sheet1").Range("A:F"))
For Each rsheet2 In Intersect(Sheets("sheet2").UsedRange.Cells,
Sheets("sheet2").Range("A:F"))
If rsheet1 = rsheet2 Then
bcolor = True
GoTo finded1:
End If
Next
finded1:
'If we never finded him, we color
If bcolor = False Then
rsheet1.Interior.ColorIndex = 4
If (rsheet1.Column <> 1) Then
Sheets("sheet1").Cells(rsheet1.Row, 1).Interior.Color = vbYellow
End If
Else
'Reset for next cell to compare
bcolor = False
End If
Next
End Sub
'============================================