Extracting a Unique List Using Complex Criteria

LearnExcl

Board Regular
Joined
Mar 17, 2010
Messages
245
Office Version
  1. 2016
Platform
  1. Windows
Hello, I have the below sample table (the actual table contains 1000 rows):

NAME CTRL CODE
Joe X3F0F3 23
Smith Y3MGG1 12
Synder D23SD4 32
Allison A3D0FH 56
Tom X3F1F3 89
Tommy E23SD4 50
Richard H61MN0 11
Ellen Y3MGG1 22
Samuel X3MGG1 90
John L23SD4 89
Rebecca C3D0FH 73
Helen S3D2FH 21
Jennifer Z3F9F3 91

I would like to extract a unique list from the list above onto another sheet based on the whether the 2nd and 3rd characters of the CTRL numbers match "3F", "3H", "22", "3D". Based on the table above, the result should look like:

JoeX3F0F323
TomZ3F1F389
JenniferX3F9F391
AllisonA3D0FH56
RebeccaC3D0FH73
HelenS3D2FH21

<tbody>
</tbody>



There are going to be cases where the list won't have any corresponding data, in case of which the results should be "".

I really appreciate your assistance with it in advance.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You can use Advanced Filter with a formula

Something like

A
B
C
D
E
F
G
H
I
1
NAME​
CTRL​
CODE​
NAME​
CTRL​
CODE​
2
Joe​
X3F0F3​
23​
TRUE​
Joe​
X3F0F3​
23​
3
Smith​
Y3MGG1​
12​
Allison​
A3D0FH​
56​
4
Synder​
D23SD4​
32​
Tom​
X3F1F3​
89​
5
Allison​
A3D0FH​
56​
Rebecca​
C3D0FH​
73​
6
Tom​
X3F1F3​
89​
Helen​
S3D2FH​
21​
7
Tommy​
E23SD4​
50​
Jennifer​
Z3F9F3​
91​
8
Richard​
H61MN0​
11​
9
Ellen​
Y3MGG1​
22​
10
Samuel​
X3MGG1​
90​
11
John​
L23SD4​
89​
12
Rebecca​
C3D0FH​
73​
13
Helen​
S3D2FH​
21​
14
Jennifer​
Z3F9F3​
91​
15

<tbody>
</tbody>


Leave E1 blank
Formula in E2
=ISNUMBER(MATCH(MID(B2,2,2),{"3F";"3H";"22";"3D"},0))

Data > Advanced filter
Pick Copy to
List Range: $A$1:$C$14
Criteria range: $E$1:$E$2
Copy to: $G$1:$I$1

Hope this helps

M.
 
Last edited:
Upvote 0
Similar to M's method:
Code:
Sub MatchC23()
  Dim r As Range, a, ur As Range, c As Range, w As Long, tf As Boolean
  Set r = [A1].CurrentRegion
  a = r.Value
  For Each r In r.Rows
    Set c = Cells(r.Row, 2)
    'ISNUMBER(MATCH(MID(B2,2,2),{"3F";"3H";"22";"3D"},0))
    tf = IsNumeric(Application.Match(Mid(c, 2, 2), Split("3F 3H 22 3D"), 0))
    If tf Then
      If ur Is Nothing Then
        Set ur = r
        Else: Set ur = Union(ur, r)
      End If
    End If
  Next r
  If ur Is Nothing Then Exit Sub
  ur.Copy [D2]
  Application.CutCopyMode = False
End Sub
 
Upvote 0
Here is another macro that you can consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub ExtractListWithConditions()
  Dim TheList As Variant
  TheList = Evaluate("IF(ISNUMBER(MATCH(MID(B2:B14,2,2),{""3F"",""3H"",""22"",""3D""},0)),A2:C14,"""")")
  Application.ScreenUpdating = False
  With Range("E1").Resize(UBound(TheList), 3)
    .Value = TheList
    .SpecialCells(xlBlanks).Delete xlShiftUp
  End With
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Here is another macro that you can consider...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub ExtractListWithConditions()
  Dim TheList As Variant
  TheList = Evaluate("IF(ISNUMBER(MATCH(MID(B2:B14,2,2),{""3F"",""3H"",""22"",""3D""},0)),A2:C14,"""")")
  Application.ScreenUpdating = False
  With Range("E1").Resize(UBound(TheList), 3)
    .Value = TheList
    .SpecialCells(xlBlanks).Delete xlShiftUp
  End With
  Application.ScreenUpdating = True
End Sub[/TD]
[/TR]
</tbody>[/TABLE]

Sir, would there be a non-macro solution to this? If I could get a list extracted from the CTRL column via posssibly an index/match formula (I have tried multiple ways, but could only get the first matching value copied all the way down, but not a unique list), I guess I will be able to take care of the rest.

Any and all help will be appreciated.
 
Upvote 0
Marcelo, is it possible to extract a list off of CTRL column without using advance filter (i.e., a dynamic formula instead)?
 
Upvote 0
Marcelo, is it possible to extract a list off of CTRL column without using advance filter (i.e., a dynamic formula instead)?

You need an array formula to extract such list

Try

A
B
C
D
E
1
NAME​
CTRL​
CODE​
CTRL List​
2
Joe​
X3F0F3​
23​
X3F0F3​
3
Smith​
Y3MGG1​
12​
A3D0FH​
4
Synder​
D23SD4​
32​
X3F1F3​
5
Allison​
A3D0FH​
56​
C3D0FH​
6
Tom​
X3F1F3​
89​
S3D2FH​
7
Tommy​
E23SD4​
50​
Z3F9F3​
8
Richard​
H61MN0​
11​
9
Ellen​
Y3MGG1​
22​
10
Samuel​
X3MGG1​
90​
11
John​
L23SD4​
89​
12
Rebecca​
C3D0FH​
73​
13
Helen​
S3D2FH​
21​
14
Jennifer​
Z3F9F3​
91​

Array formula in E2 copied down
=IFERROR(INDEX(B:B,SMALL(IF(ISNUMBER(MATCH(MID(B$2:B$14,2,2),{"3F";"3H";"22";"3D"},0)),ROW(B$2:B$14)),ROWS(E$2:E2))),"")
Ctrl+Shift+Enter

M.
 
Upvote 0
You need an array formula to extract such list

Try

A
B
C
D
E
1
NAME​
CTRL​
CODE​
CTRL List​
2
Joe​
X3F0F3​
23​
X3F0F3​
3
Smith​
Y3MGG1​
12​
A3D0FH​
4
Synder​
D23SD4​
32​
X3F1F3​
5
Allison​
A3D0FH​
56​
C3D0FH​
6
Tom​
X3F1F3​
89​
S3D2FH​
7
Tommy​
E23SD4​
50​
Z3F9F3​
8
Richard​
H61MN0​
11​
9
Ellen​
Y3MGG1​
22​
10
Samuel​
X3MGG1​
90​
11
John​
L23SD4​
89​
12
Rebecca​
C3D0FH​
73​
13
Helen​
S3D2FH​
21​
14
Jennifer​
Z3F9F3​
91​

Array formula in E2 copied down
=IFERROR(INDEX(B:B,SMALL(IF(ISNUMBER(MATCH(MID(B$2:B$14,2,2),{"3F";"3H";"22";"3D"},0)),ROW(B$2:B$14)),ROWS(E$2:E2))),"")
Ctrl+Shift+Enter
Just noting that the OP wanted to output three columns of data per row, not just one.
 
Upvote 0
Marcelo, is it possible to extract a list off of CTRL column without using advance filter (i.e., a dynamic formula instead)?

Just noting that the OP wanted to output three columns of data per row, not just one.

Rick,

I understood that in his last post he asked to extract only the CTRL column.

By the way, after extracting CTRL column, regular INDEX/MATCH formulas can easily extract the other columns.

M.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,899
Messages
6,122,155
Members
449,068
Latest member
shiz11713

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