Sub compareRange()
If Worksheets("Sheet1").Range("A14:C14") = Worksheets("Sheet1").Range("A15:C15") Then
MsgBox "Two Ranges are the same"
End If
'MsgBox "Two Ranges are the same"
End Sub
Giving that A14:C14(1,2,3) and A15:C15(1,2,3) has same values, i am getting a type mismatch error. How am i suppose to compare two ranges like this?
You don't need VBA for that. Try this array formula:
After typing in the formula, use Ctrl+Shift+Enter to set it as an array formula.
It will return TRUE if the ranges are equal and FALSE if they aren't.
If you need to do this using VBA, try this:
EDIT: I don't like ActiveSheet, and I don't like the hard-coded ranges, so here is a more complete snippet:
You just can't do this. This is not how ranges work. You need to iterate through each cell in the ranges using some kind of for loop. You may want to add checks so that you spot cases where the number of cells is not equal (obviously the ranges are different if that is the case).