(vba) compare two arrays, range by range

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hi
VBA Code:
Sub compare_two_array()
   Dim B As Variant
   Dim A As Variant

   B = Range("B2:F13").Value
   A = Range("I2:M13").Value
   counter = 1
   While counter <= UBound(B)
      X = B(counter, 1)
      Y = A(counter, 1)
      If X = Y Then
         Range("o2:o13").Value = "match"
         
      Else: Range("o2:o13").Value = "no"
      End If
      counter = counter + 1
   Wend
End Sub

Trying to compare two arrays, "range by range".

I will explained the obvious to avoid wrong interpretation

If I have the following sequences in an array
(this is a small example only)
1 2 3
1 3 2
2 3 1
2 1 3
3 2 1
3 1 2
And I want to compare “range” by “range” against the second array
2 3 1
4 5 6
3 1 2
The duplicates here will be only two 231 and 312
Well, my real data location is (“B2:F5000”) array1
To compare against (“I2:M100”)
On column I would like to see “match” or “no”

Thank you for your time, reading this.
1658706852832.png

Is just a little ilustration, thanks.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Snasui, I will be arround your blog for sure, thanks. see you there
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,727
Members
449,049
Latest member
MiguekHeka

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top