Unique list from multiple columns with advanced filter

juanbolas

New Member
Joined
Dec 3, 2014
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hello

I'm trying to get a unique list of names using the advanced filter but my code is just showing the first unique item.

Can someone help me please?

Thanks in advance

VBA Code:
Sub Proveedores_UniqueList()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim LR As Long

Set wsSource = ThisWorkbook.Sheets("DB_PDP").Range("PDP_ProveedoresRange")
Set wsTarget = ThisWorkbook.Sheets("Proveedores_UniqueList")

Set rngTopCell = wsSource.Offset(1, 0)
Set rngBottomCell = wsSource.Offset(wsSource.CurrentRegion.Rows.Count - 1, 0)
Set rngEntireRange = Range(rngTopCell, rngBottomCell)

rngEntireRange.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wsTarget.Range("A:A"), Unique:=True

End Sub
 
You did not address these questions

Expected results: I assume that Prov 34 is an error?

Does this have to be vba? What about this formula solution?

juanbolas.xlsm
A
1Prov 1
2Prov 2
3Prov 3
4Prov 4
5Prov 6
6Prov 7
7Prov 9
8Prov 10
9Prov 11
10Prov 12
11Prov 13
12Prov 14
13Prov 15
14Prov 16
15Prov 17
16Prov 18
17Prov 19
18Prov 5
19
Proveedores_UniqueList
Cell Formulas
RangeFormula
A1:A18A1=LET(a,DB_PDP!X11:Z100,r,ROWS(a),seq,SEQUENCE(r*COLUMNS(a),,0),arr,INDEX(a,MOD(seq,r)+1,seq/r+1),UNIQUE(FILTER(arr,arr<>"")))
Dynamic array formulas.
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Prov 34 is NOT an error; it's one of the data items.
Hmm again. That value was included in your response to
What is your expected result for that sample data?
I am unable to find Prov 34 anywhere in the sample data in post #6 sample data (or in post #1)

No, it's just X11:Z11 the headers for each of the three columns
Again looking at the sample data in post #6, if it is the headers, then surely it is X10:Z10?

The first thing that I usually do to try to help in the forum is to set up a sample worksheet like yours and then try to produce the results you say you want. That is difficult if the information being provided is wrong or confusing. To get the fastest and best help, please try to give careful & accurate information.

So, for the suggestion below, I am assuming
- that Prov 34 is an error in the expected results for the sample data provided in post 6
- that the names range "PDP_ProveedoresRange" is X10:Z10 for the sample data provided in post 6

Try this with a copy of your workbook.
(I have not used Advanced Filter as you requested because that will not produce a single column unique list from a multi-column range.)
VBA Code:
Sub Proveedores_UniqueList_v2()
  Dim wsSource As Worksheet, wsTarget As Worksheet
  Dim d As Object
  Dim a As Variant
  Dim rws As Long, i As Long, j As Long

  Set wsSource = ThisWorkbook.Sheets("DB_PDP")
  Set wsTarget = ThisWorkbook.Sheets("Proveedores_UniqueList")
  Set d = CreateObject("Scripting.Dictionary")
 
  With wsSource.Range("PDP_ProveedoresRange")
    rws = .EntireColumn.Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row - .Row
    a = .Offset(1).Resize(rws).Value
  End With
  For j = 1 To UBound(a, 2)
    For i = 1 To UBound(a, 1)
      If Not IsEmpty(a(i, j)) Then d(a(i, j)) = 1
    Next i
  Next j
 
  wsTarget.Range("A1").Resize(d.Count).Value = Application.Transpose(d.Keys)
End Sub

For the sample data in post 6, this is the result of the above code

juanbolas.xlsm
A
1Prov 1
2Prov 2
3Prov 3
4Prov 4
5Prov 6
6Prov 7
7Prov 9
8Prov 10
9Prov 11
10Prov 12
11Prov 13
12Prov 14
13Prov 15
14Prov 16
15Prov 17
16Prov 18
17Prov 19
18Prov 5
19
Proveedores_UniqueList
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

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