Get the list from a table headers drop down

nemmi69

Well-known Member
Joined
Mar 15, 2012
Messages
938
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Instead of reinventing the wheel is there a way to get the unique list that shows in a headers drop down?
 
because i didn't copy the entire code as thats not allowed
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
because i didn't copy the entire code as thats not allowed
Fair enough, but all we have to test with and comment on is what you actually give us - & we are trying to help. ;)

BTW, did you try the one-liner?
 
Upvote 0
I tried the 1 liner but it didnt want to play
 
Upvote 0
I tried the 1 liner but it didnt want to play
"didn't want to play" is very vague

Did it give an error message?
Return wrong values?
Do nothing?
Crash excel?
Something else?

Here is my sample table

nemmi69.xlsm
ABCD
1
2UnitAction
32Initial
44Replacement
53Initial
64Replacement
71Repair
8
Sheet1


And my code

VBA Code:
Sub Test()
  Dim TblId As ListObject
  Dim TblHdr As String
  
  Set TblId = ActiveSheet.ListObjects(1)
  Dim LArr As Variant
  TblHdr = "Action"
  LArr = Evaluate("sort(unique(" & TblId.Name & "[" & TblHdr & "]))")
End Sub

And the result held in LArr. In what way is that not what you are after?

1677239592292.png
 
Upvote 0
Ah, I am trying to gather the unique elements into an array for use with a report macro
 
Upvote 0
Ah, I am trying to gather the unique elements into an array for use with a report macro
.. which is exactly what my code does, isn't it?

.. or is it that my array is a 2-D array whereas yours was a 1-D array? If that was the issue then try this modification.
Rich (BB code):
Sub Test()
  Dim TblId As ListObject
  Dim TblHdr As String
  Dim LArr As Variant
  
  Set TblId = ActiveSheet.ListObjects(1)  '<- Set to your particular ListObject/Table
  TblHdr = "Action"                       '<- Set to your particular table heading
  LArr = Application.Transpose(Evaluate("sort(unique(" & TblId.Name & "[" & TblHdr & "]))"))
End Sub

1677276823484.png
 
Upvote 0
Sorry for late response. Busy at work. Yes @Peter_SSs your method works . Thanks! :)
 
Upvote 0

Forum statistics

Threads
1,215,521
Messages
6,125,307
Members
449,218
Latest member
Excel Master

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