ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Get Autofilter options (VBA) (https://www.excelbanter.com/excel-discussion-misc-queries/161694-get-autofilter-options-vba.html)

ashish128

Get Autofilter options (VBA)
 
Hi to all,

I didnt knew what to type to search and therefore am posting this
request.

Whenever we autofilter a range and select any field then we get a
dropdown list of unique entries in that field.

1. If there is only one item then how to get that.

eg.

A
5
5
5
5

If I autofilter on column A then it will only contain 5. How can I get
this value using VBA

2. how to get all of the the autofilter options?
eg.
A
1
2
3
1
2
3
1
2
3
if I autofilter on column A then the available options will be

A
1
2
3

howto get them using VBA.

Kindly advice.

With Regards

Ashish Sharma


Pete_UK

Get Autofilter options (VBA)
 
Here's one I posted the other day:

Sub uniques_from_A()
'
' 09/10/2007 by Pete Ashurst
'
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Copy
Sheets.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
ActiveCell.Range("A1:A" & _
Cells(Rows.Count, "A").End(xlUp).Row).AdvancedFilter _
Action:=xlFilterCopy, CopyToRange _
:=ActiveCell.Offset(0, 2).Range("A1"), Unique:=True
Columns("A:B").Delete Shift:=xlToLeft
Range("A1").Select
End Sub


It will give you the list of unique values from column A of the
current sheet (assume heading is on row1 - you must have a heading)
and
sorted.


It does not include the choices "All", "Top 10", "Custom ..." which
the Autofilter pull-down shows at the top, nor "Blanks" or "Non-
blanks" shown at the bottom.


Hope this helps.


Pete



On Oct 11, 9:47 am, ashish128 wrote:
Hi to all,

I didnt knew what to type to search and therefore am posting this
request.

Whenever we autofilter a range and select any field then we get a
dropdown list of unique entries in that field.

1. If there is only one item then how to get that.

eg.

A
5
5
5
5

If I autofilter on column A then it will only contain 5. How can I get
this value using VBA

2. how to get all of the the autofilter options?
eg.
A
1
2
3
1
2
3
1
2
3
if I autofilter on column A then the available options will be

A
1
2
3

howto get them using VBA.

Kindly advice.

With Regards

Ashish Sharma




ashish128

Get Autofilter options (VBA)
 
On Oct 11, 5:47 pm, Pete_UK wrote:
Here's one I posted the other day:

Sub uniques_from_A()
'
' 09/10/2007 by Pete Ashurst
'
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Copy
Sheets.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
ActiveCell.Range("A1:A" & _
Cells(Rows.Count, "A").End(xlUp).Row).AdvancedFilter _
Action:=xlFilterCopy, CopyToRange _
:=ActiveCell.Offset(0, 2).Range("A1"), Unique:=True
Columns("A:B").Delete Shift:=xlToLeft
Range("A1").Select
End Sub

It will give you the list of unique values from column A of the
current sheet (assume heading is on row1 - you must have a heading)
and
sorted.

It does not include the choices "All", "Top 10", "Custom ..." which
the Autofilter pull-down shows at the top, nor "Blanks" or "Non-
blanks" shown at the bottom.

Hope this helps.

Pete

On Oct 11, 9:47 am, ashish128 wrote:



Hi to all,


I didnt knew what to type to search and therefore am posting this
request.


Whenever we autofilter a range and select any field then we get a
dropdown list of unique entries in that field.


1. If there is only one item then how to get that.


eg.


A
5
5
5
5


If I autofilter on column A then it will only contain 5. How can I get
this value using VBA


2. how to get all of the the autofilter options?
eg.
A
1
2
3
1
2
3
1
2
3
if I autofilter on column A then the available options will be


A
1
2
3


howto get them using VBA.


Kindly advice.


With Regards


Ashish Sharma- Hide quoted text -


- Show quoted text -


Thanks pal but sorry to say that i have no heading.


Pete_UK

Get Autofilter options (VBA)
 
Well, put one in temporarily and delete it afterwards.

Pete

On Oct 11, 4:39 pm, ashish128 wrote:
On Oct 11, 5:47 pm, Pete_UK wrote:





Here's one I posted the other day:


Sub uniques_from_A()
'
' 09/10/2007 by Pete Ashurst
'
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Copy
Sheets.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
ActiveCell.Range("A1:A" & _
Cells(Rows.Count, "A").End(xlUp).Row).AdvancedFilter _
Action:=xlFilterCopy, CopyToRange _
:=ActiveCell.Offset(0, 2).Range("A1"), Unique:=True
Columns("A:B").Delete Shift:=xlToLeft
Range("A1").Select
End Sub


It will give you the list of unique values from column A of the
current sheet (assume heading is on row1 - you must have a heading)
and
sorted.


It does not include the choices "All", "Top 10", "Custom ..." which
the Autofilter pull-down shows at the top, nor "Blanks" or "Non-
blanks" shown at the bottom.


Hope this helps.


Pete


On Oct 11, 9:47 am, ashish128 wrote:


Hi to all,


I didnt knew what to type to search and therefore am posting this
request.


Whenever we autofilter a range and select any field then we get a
dropdown list of unique entries in that field.


1. If there is only one item then how to get that.


eg.


A
5
5
5
5


If I autofilter on column A then it will only contain 5. How can I get
this value using VBA


2. how to get all of the the autofilter options?
eg.
A
1
2
3
1
2
3
1
2
3
if I autofilter on column A then the available options will be


A
1
2
3


howto get them using VBA.


Kindly advice.


With Regards


Ashish Sharma- Hide quoted text -


- Show quoted text -


Thanks pal but sorry to say that i have no heading.- Hide quoted text -

- Show quoted text -





All times are GMT +1. The time now is 12:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com