• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA - If two ranges are equal, then issue [SOLVED]

cacos

Member
Hi everyone, I'm having some trouble with something that's really simple and can't get it to work. Hopefully someone will be able to shed some light.


Basically, I need VBA to compare two ranges (of the same lenght) and, if they are equal, do something.


Like this:

[pre]
Code:
If Sheet1.Range("A1:A10").Value = Sheet1.Range("B1:B10").Value Then 'and here my code
[/pre]

Basically, if values in A1:A10 are exactly the same (same order and everything) as B1:B10, run some code.


Thanks!
 
Here's a quick and dirty way -

[pre]
Code:
Sub foo()
If Sheet1.[=AND(A1:A10=B1:B10)] Then
RunSomeCode
End If
End Sub

Sub RunSomeCode()
MsgBox "ranges are the same"
End Sub
[/pre]
 
Back
Top