Hello,
This time, I have to write a sub that checks if a value is duplicate in two columns. If it is, a message box should appear saying "blah." If it is not, a message box should appear saying "okay."
I have written a code. However, when I run it, I always get the message box saying "okay." This should not happen because there are definitely identical values in the two columns. Any help fixing my code would be great.
Sub Compare()
Dim r1 As Range, r2 As Range, rng1 As Range, rng2 As Range
Set r1 = Worksheets("Sheet1").Range("A2:A11")
Set r2 = Worksheets("Sheet1").Range("B2:B11")
For Each rng1 In r1
For Each rng2 In r2
If rng1 = rng2 Then
MsgBox ("blah")
Else
MsgBox ("okay")
End If
Next
Next
End Sub
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
Bookmarks