Match two sets of numbers regardless of order

wcthrill

Board Regular
Joined
Nov 28, 2005
Messages
80
Hi

Im trying to figure how Excel can match a set of numbers of the position.
So for example I would like Excel to provide a true result of the two below numbers
as they both contain the same numbers but in a different order

4215 5142
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
This can probably be done with a formula, but here is some vba in case you want to use it.

Code:
Sub t()
Dim i As Long
a = 4215
b = 5142
For i = 1 To 4
    If InStr(b, Mid(a, i, 1)) = 0 Then
        x = x + 1
    End If
Next
    If x > 0 Then
        MsgBox "No Match"
    Else
        MsgBox "Matches"
    End If
End Sub
 
Upvote 0
The following array formula (to be entered using Ctrl+Shift+Enter, not just Enter) works for the posted example (yet needs more testing):

=SUM(IF(ISNUMBER(FIND((ROW($1:$10)-1)&"",A1)),ROW($1:$10)^ROW($1:$10)))+LEN(A1)=SUM(IF(ISNUMBER(FIND((ROW($1:$10)-1)&"",B1)),ROW($1:$10)^ROW($1:$10)))+LEN(B1)
 
Upvote 0
One formula option:

ABCD
142155142TRUETRUE

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet3

Worksheet Formulas
CellFormula
C1=AND(SMALL(MID(A1,{1,2,3,4},1)+0,{1,2,3,4})=SMALL(MID(B1,{1,2,3,4},1)+0,{1,2,3,4}))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
D1{=IFERROR(AND(SMALL(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)+0,ROW(INDIRECT("1:"&LEN(A1))))=SMALL(MID(B1,ROW(INDIRECT("1:"&LEN(B1))),1)+0,ROW(INDIRECT("1:"&LEN(B1))))),FALSE)}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



The formula in C1 works for 2 4-digit numbers. Not too terrible. The formula in D1 works for 2 numbers of arbitrary size (a bit messier!) Both only work on numbers, no letters.
 
Upvote 0

Forum statistics

Threads
1,218,123
Messages
6,140,615
Members
450,299
Latest member
ebculver

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