Let say we have this range
Column A
1234
2345
7891
1234
6501
and so on
Column B
4321
5584
5016
5231
2345
and so on
I just want a formula that can identify if number in column A is contained column B either in straight or permuted way
Example
1234 is in column B as 4321
2345 is in column B as 2345
6501 is in column B as 5016
Thank You![]()
Last edited by NBVC; 11-25-2011 at 11:45 AM.
Try this user defined function.
Paste this into a new module in the VBA editor (alt F11).Function FINDSPECIAL(Range1 As Range, Range2 As Range) As Boolean Dim Range1Array() As String Dim Range2Array() As String Dim TempRange As String Dim N As Integer Dim M As Integer Dim Range1Len As Integer Dim Cell As Range Range1Len = Len(Range1) ReDim Range1Array(Range1Len - 1) For N = 1 To Range1Len Range1Array(N - 1) = Mid(Range1.Value, N, 1) Next N 'Bubble sort For N = 0 To Range1Len - 1 For M = 0 To Range1Len - 1 If Asc(Range1Array(N)) > Asc(Range1Array(M)) Then TempRange = Range1Array(N) Range1Array(N) = Range1Array(M) Range1Array(M) = TempRange End If Next M Next N For Each Cell In Range2 If Len(Cell) = Range1Len Then ReDim Range2Array(Range1Len - 1) For N = 1 To Range1Len Range2Array(N - 1) = Mid(Cell.Value, N, 1) Next N 'Bubble sort For N = 0 To Range1Len - 1 For M = 0 To Range1Len - 1 If Asc(Range2Array(N)) > Asc(Range2Array(M)) Then TempRange = Range2Array(N) Range2Array(N) = Range2Array(M) Range2Array(M) = TempRange End If Next M Next N FINDSPECIAL = True For N = 0 To Range1Len - 1 If Range1Array(N) <> Range2Array(N) Then FINDSPECIAL = False Exit For End If Next N End If If FINDSPECIAL = True Then Exit Function Next Cell End Function
In the original sheet, type in =FINDSPECIAL(A1,$B$1:$B$5) into C1 and copy down.
Martin
Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.
If my solution has saved you time and/or money, please consider donating to Cancer Research UK.
Also, if you dealing only with 4 digit numbers, with a formula.
=SUMPRODUCT(ISNUMBER(SEARCH(MID(A1,1,1),$B$1:$B$5))*ISNUMBER(SEARCH(MID(A1,2,1),$B$1:$B$5))*ISNUMBER(SEARCH(MID(A1,3,1),$B$1:$B$5))*ISNUMBER(SEARCH(MID(A1,4,1),$B$1:$B$5)))
Microsoft MVP - Excel
Where there is a will there are many ways. Pick One!
Please read the Forum Rules
If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below
Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.
Preferred Charities: Lupus Canada and Sick Kids Foundation.
Feel Free to Donate if you want to, for the assistance you received today.
Thank you NBVC and mrice!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks