title: Compare two Ranges VBA
body: <p>I am trying to compare to ranges in excel with the following VBA code:</p>
  
  <pre><code>Sub CompareTwoRanges()
  Dim wb As Workbook
  Dim ws1 As Worksheet
  Dim ws2 As Worksheet
  Dim rng1 As Range
  Dim rng2 As Range
  
  Set wb = ThisWorkbook
  Set ws1 = wb.Sheets("Sheet1")
  Set ws2 = wb.Sheets("Sheet2")
  Set rng1 = ws1.Range("A14:C14")
  Set rng2 = ws2.Range("N3:P3")
  
  If rangesAreEqual(rng1, rng2, ws1, ws2) Then
  MsgBox "The ranges are equal."
  Else
  MsgBox "Sorry. The ranges are NOT equal."
  End If
  End Sub
  
  Function rangesAreEqual(rng1 As Range, rng2 As Range, _
  ws1 As Worksheet, ws2 As Worksheet) As Boolean
  ' booleans default to false
  ' verify ranges have same dimensions
  If rng1.Columns.Count &lt;&gt; rng2.Columns.Count Then Exit Function
  If rng1.Rows.Count &lt;&gt; rng2.Rows.Count Then Exit Function
  
  ' ranges are the same size. are their contents equal?
  rangesAreEqual = ws1.Evaluate("=AND(EXACT(" &amp; ws1.Name &amp; "!" &amp; _
  rng1.Address &amp; "," &amp; ws2.Name &amp; "!" &amp; rng2.Address &amp; "))")
  End Function
  </code></pre>
  
  <p>However I am getting the error Type Mismatch.</p>
  
  <p>Anyone have ideas on what the problem is?</p>
  
  <p>I got this code from another post (<a href="https://stackoverflow.com/questions/17868131/compare-two-row-ranges-with-same-number-of-cells/17868428#17868428?newreg=48dcaff1ae8e4c7b8af71d8a4d0d7b04">Compare Two Ranges</a>) however I can not comment to ask the person who posted the code why I might be getting this problem.</p>