View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Shawn O'Donnell Shawn O'Donnell is offline
external usenet poster
 
Posts: 42
Default compare values in 2 ranges

"Martin Wheeler" wrote:
I need to compare the values in ranges M1:M3 to CE7:CE9. The values, in the
current worksheet, are 3,8,5 and 3,5,8. These values are the same but not in
the same order. The order is not important. What I need to know is if the
values are the same, regardless of order.


How about copying the ranges to arrays, sorting the arrays, then stepping
through the arrays to see if all the elements match?

Remember that when you copy a range to a Variant array, you get a
two-dimensional array. To transfer the range values to an array you do
something like this:

For i = 1 to uBound(range_A, 1)
array_A(i) = range_A(i, 1)
next i

To sort the array, use code someone else checked. You'll find code for two
different algorithms he http://support.microsoft.com/?kbid=213818