![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Join Date: Jul 2002
Posts: 78
|
Is there a more elegant way of comparing 2 array than is shown below ?
I just want to check if the 2 arrays are exactly identical...... for i = 1 to 10 if array1(i)=array2(i) then....... next i TIA.... |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Jul 2002
Posts: 32,030
|
I don't know about more elegant, but it would be quicker to test for inequality and exit the loop when they don't match.
Code:
x = True
For i = LBound(array1) to UBound(array1)
If array1(i) <> array2(i) Then
x = False
Exit For
End If
Next i
If x = True Then
MsgBox "Match"
Else
MsgBox "Item " & i & " does not match"
End If
|
|
|
|
|
|
#3 |
|
Join Date: Jul 2002
Posts: 78
|
Yours look more robust to me.... I thought there would be some kind of match commando ...quess not.
Thanks ! |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Jul 2002
Posts: 32,030
|
If you don't need to know which item mismatches you could use the Join function (Excel 2000 and above):
Code:
If Join(array1, "") = Join(array2, "") Then MsgBox "Match" Else MsgBox "Mismatch" End If |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|