Extract unmatched of 9 patterns till the 9 patterns remains 0 and continue new search

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000</SPAN></SPAN>
Hi,
</SPAN></SPAN>

I have 9 unique patterns in the cells C4:K4 and some results in the cells D6:J44, My request is I need a macro which can extract unmatched patterns after the matching results out of 9 patterns and copy them in to N4:T44.
</SPAN></SPAN>

Start looking in the first result row num 6 as in first row find 5 match, remaining 4 unmatched patterns copy them in to columns N:T, look in to next result row num 7 found 3 more matches, now remaining 1 unmatched pattern copy them in to columns N:T, keep looking in to next result row num 8 found 1 more match, now remaining unmatched 0 exit, And continue next new search in to the next rows and follow the same search method...
</SPAN></SPAN>

Example sheet...
</SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQRSTUV
1
2RemainingRemainingRemainingRemainingRemainingRemainingRemaining
3Patt1Patt2Patt3Patt4Patt5Patt6Patt7Patt8Patt9UnmatchedUnmatchedUnmatchedUnmatchedUnmatchedUnmatchedUnmatched
41 | 11 | X1 | 2X | 1X | XX | 22 | 12 | X2 | 2Of 9 PattOf 9 PattOf 9 PattOf 9 PattOf 9 PattOf 9 PattOf 9 Patt
5All 9 OutRemaining
61 | 12 | 1X | 2X | X1 | 22 | X1 | X2 | 2X | 1
72 | X1 | X2 | 2X | 1
8X | 190
92 | 11 | 11 | 2X | 11 | X2 | XX | XX | 22 | 2
10X | XX | 22 | 290
111 | 22 | 2X | 11 | 12 | X1 | X2 | 1X | 2X | X
122 | X1 | X2 | 1X | 2X | X
13X | 2X | X
14X | X
15X | X
16X | X
17X | X90
182 | 1X | 21 | X1 | 1X | XX | 11 | 22 | 22 | X
19X | 11 | 22 | 22 | X
201 | 22 | 22 | X
212 | X90
22X | 1X | XX | 21 | 12 | 12 | 21 | 21 | X2 | X
231 | 21 | X2 | X
242 | X
252 | X
262 | X90
271 | 12 | 21 | X2 | XX | 11 | 2X | 2X | X2 | 1
28X | 11 | 2X | 2X | X2 | 190
292 | 1X | 1X | X2 | 21 | 12 | X1 | 2X | 21 | X
301 | 2X | 21 | X
31X | 21 | X
32X | 21 | X90
332 | X1 | 11 | 22 | 22 | 1X | XX | 11 | XX | 2
34X | 11 | XX | 290
351 | 2X | X1 | X2 | 11 | 1X | 2X | 12 | X2 | 2
361 | 1X | 2X | 12 | 2
372 | X2 | 2
382 | 290
392 | 11 | 11 | X1 | 2X | 12 | 2X | 22 | XX | X
40X | 22 | XX | X
41X | X90
421 | 22 | X2 | 21 | 1X | 21 | X2 | 1X | 1X | X
431 | X2 | 1X | 1X | X
44X | 1X | X
45
46
47
Sheet4


Thank you in advance
</SPAN></SPAN>

Regards,
</SPAN></SPAN>
Kishan
</SPAN></SPAN>
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi Kishan,

Try this:

Code:
Option Explicit
Sub Macro1()

    Dim clnMyUniqueArray As New Collection
    Dim rngMyCell As Range
    Dim lngLastRow As Long
    Dim lngMyRow As Long
    Dim lngMyCol As Long
    Dim i As Integer
    
    Application.ScreenUpdating = False

    For Each rngMyCell In Range("C4:K4")
        clnMyUniqueArray.Add rngMyCell, CStr(rngMyCell)
    Next rngMyCell
    
    lngLastRow = Range("C:K").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    For lngMyRow = 6 To lngLastRow
        For lngMyCol = 3 To 11 'Columns C to K
            If Len(Cells(lngMyRow, lngMyCol)) > 0 Then
                For i = 1 To clnMyUniqueArray.Count
                    If CStr(Cells(lngMyRow, lngMyCol)) = CStr(clnMyUniqueArray(i)) Then
                        clnMyUniqueArray.Remove (i)
                        Exit For
                    End If
                Next i
            End If
        Next lngMyCol
        If clnMyUniqueArray.Count > 0 Then
            For i = 1 To clnMyUniqueArray.Count
                Range("N" & lngMyRow).Offset(0, i - 1).Value = CStr(clnMyUniqueArray(i))
            Next i
        Else
            For Each rngMyCell In Range("C4:K4")
                clnMyUniqueArray.Add rngMyCell, CStr(rngMyCell)
            Next rngMyCell
            Range("L" & lngMyRow).Value = clnMyUniqueArray.Count
            Range("M" & lngMyRow).Value = 0
        End If
    Next lngMyRow
    
    Application.ScreenUpdating = True
    
End Sub

Note the remaining unmatched items for each row are outputted in the same order as they were added from the array i.e. cells C4:K4) not how you've shown (hope that's not a problem).

Regards,

Robert
 
Upvote 0
Hi Kishan,

Try this:

Code:
Option Explicit
Sub Macro1()

    Dim clnMyUniqueArray As New Collection
    Dim rngMyCell As Range
    Dim lngLastRow As Long
    Dim lngMyRow As Long
    Dim lngMyCol As Long
    Dim i As Integer
    
    Application.ScreenUpdating = False

    For Each rngMyCell In Range("C4:K4")
        clnMyUniqueArray.Add rngMyCell, CStr(rngMyCell)
    Next rngMyCell
    
    lngLastRow = Range("C:K").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    For lngMyRow = 6 To lngLastRow
        For lngMyCol = 3 To 11 'Columns C to K
            If Len(Cells(lngMyRow, lngMyCol)) > 0 Then
                For i = 1 To clnMyUniqueArray.Count
                    If CStr(Cells(lngMyRow, lngMyCol)) = CStr(clnMyUniqueArray(i)) Then
                        clnMyUniqueArray.Remove (i)
                        Exit For
                    End If
                Next i
            End If
        Next lngMyCol
        If clnMyUniqueArray.Count > 0 Then
            For i = 1 To clnMyUniqueArray.Count
                Range("N" & lngMyRow).Offset(0, i - 1).Value = CStr(clnMyUniqueArray(i))
            Next i
        Else
            For Each rngMyCell In Range("C4:K4")
                clnMyUniqueArray.Add rngMyCell, CStr(rngMyCell)
            Next rngMyCell
            Range("L" & lngMyRow).Value = clnMyUniqueArray.Count
            Range("M" & lngMyRow).Value = 0
        End If
    Next lngMyRow
    
    Application.ScreenUpdating = True
    
End Sub

Note the remaining unmatched items for each row are outputted in the same order as they were added from the array i.e. cells C4:K4) not how you've shown
(hope that's not a problem).

Regards,

Robert
Wonderful! Robert, macro is extremely perfect.:) Even I like the unmatched pattern order as they are showing now as per cells (C4:K4) orders.</SPAN></SPAN>

I do appreciate your help and time you spent to solve my query :beerchug:
</SPAN></SPAN>
Have a good day and Good Luck
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Kishan
</SPAN></SPAN>
 
Last edited:
Upvote 0
Thanks for letting us know and you're welcome :) Thanks also for the thanks and likes ;)
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,168
Members
452,615
Latest member
bogeys2birdies

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