YourBroLucas
New Member
- Joined
- Jul 11, 2022
- Messages
- 29
- Office Version
- 2016
- Platform
- Windows
Hello,
I wish to export the unique values of 3 columns out of a dynamic table.
The macro down below works for 2 out of 3 columns, and I don't know why.
The V column thus remains empty.
On a sidenote, this macro is meant to provide a unique list of values in order to create a double-free dropdown list elsewhere, for the sake of comfort.
Also, said macro turns my table filters off, for reasons probably obvious to many here (please no forehead slapping).
I'll be more than happy to read pieces of advice you might have!
May your wisdom enlighten me! ☺
The macro:
I wish to export the unique values of 3 columns out of a dynamic table.
The macro down below works for 2 out of 3 columns, and I don't know why.
The V column thus remains empty.
On a sidenote, this macro is meant to provide a unique list of values in order to create a double-free dropdown list elsewhere, for the sake of comfort.
Also, said macro turns my table filters off, for reasons probably obvious to many here (please no forehead slapping).
I'll be more than happy to read pieces of advice you might have!
May your wisdom enlighten me! ☺
The macro:
VBA Code:
Option Explicit
Sub ExtractUniqueValues()
Dim shtGen As Worksheet, shtVar As Worksheet
Dim lr As Long
Dim rngP As Range, goP As Range
Dim rngBDC As Range, goBDC As Range
Dim rngCOM As Range, goCOM As Range
Set shtGen = ActiveWorkbook.Worksheets("Tab_Général")
Set shtVar = ActiveWorkbook.Worksheets("Variables")
lr = shtGen.Range("A" & Rows.Count).End(3).Row
Set rngP = shtGen.Range("E16:E" & lr)
Set goP = shtVar.Range("R2")
rngP.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=rngP, CopyToRange:=goP, Unique:=True
If shtGen.FilterMode = True Then shtGen.ShowAllData
Set rngBDC = shtGen.Range("G16:G" & lr)
Set goBDC = shtVar.Range("T2")
rngBDC.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=rngBDC, CopyToRange:=goBDC, Unique:=True
If shtGen.FilterMode = True Then shtGen.ShowAllData
Set rngCOM = shtGen.Range("F16:F" & lr)
Set goCOM = shtVar.Range("V2")
rngCOM.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=rngCOM, CopyToRange:=goCOM, Unique:=True
' I've tried to delete this one line, but nothing changed.
If shtGen.FilterMode = True Then shtGen.ShowAllData
End Sub