Unique values export working only for 2 out of 3 columns?

YourBroLucas

New Member
Joined
Jul 11, 2022
Messages
29
Office Version
  1. 2016
Platform
  1. 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:
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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Alright so for those passing by, the reason it was not working was because the first cell in column F (shtGen) was empty...

I'm a real bozo at times.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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