Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Advanced Filter Macro with InputBox use

I'd like to:

Highlight/Select a range say B5:B25
That contains (bob, carol, ted, ted, bob, alice, carol,
bob, ted, alice, carol......) << only 4 unique names are
in B5:B25 (bob, ted, carol alice)

Then run a macro that will using an Input box (where I
supply a cell reference, like J1 {enter}
and an Advance Filter is run and pastes to Range J1:J4
Alice, Bob, Carol
Ted (alphabetically).

Can this be done?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Advanced Filter Macro with InputBox use

You can use code similar to the following:

'=======================
Sub GetUnique()
Dim rng As Range

If Selection.Columns.Count 1 Then
MsgBox "Please select cells in one column only"
Exit Sub
End If
If Selection.Row = 1 Then
MsgBox "Selection cannot include row 1"
Exit Sub
End If
Set rng = Selection.Offset(-1, 0) _
.Resize(Selection.Rows.Count + 1, 1)

Columns("J:J").Clear
rng.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("J1"), Unique:=True
Range("J1").Delete shift:=xlUp
Range("J1").CurrentRegion.Sort Key1:=Range("J1"), _
Order1:=xlAscending, Header:=xlGuess
End Sub
'==========================

wrote:
I'd like to:

Highlight/Select a range say B5:B25
That contains (bob, carol, ted, ted, bob, alice, carol,
bob, ted, alice, carol......) << only 4 unique names are
in B5:B25 (bob, ted, carol alice)

Then run a macro that will using an Input box (where I
supply a cell reference, like J1 {enter}
and an Advance Filter is run and pastes to Range J1:J4
Alice, Bob, Carol
Ted (alphabetically).

Can this be done?



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default Advanced Filter Macro with InputBox use

Debra:
Thanks so much for the code; I pledge to understand it over the weekend;
Enjoy yours.........
Jim May

"Debra Dalgleish" wrote in message
...
You can use code similar to the following:

'=======================
Sub GetUnique()
Dim rng As Range

If Selection.Columns.Count 1 Then
MsgBox "Please select cells in one column only"
Exit Sub
End If
If Selection.Row = 1 Then
MsgBox "Selection cannot include row 1"
Exit Sub
End If
Set rng = Selection.Offset(-1, 0) _
.Resize(Selection.Rows.Count + 1, 1)

Columns("J:J").Clear
rng.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("J1"), Unique:=True
Range("J1").Delete shift:=xlUp
Range("J1").CurrentRegion.Sort Key1:=Range("J1"), _
Order1:=xlAscending, Header:=xlGuess
End Sub
'==========================

wrote:
I'd like to:

Highlight/Select a range say B5:B25
That contains (bob, carol, ted, ted, bob, alice, carol,
bob, ted, alice, carol......) << only 4 unique names are
in B5:B25 (bob, ted, carol alice)

Then run a macro that will using an Input box (where I
supply a cell reference, like J1 {enter}
and an Advance Filter is run and pastes to Range J1:J4
Alice, Bob, Carol
Ted (alphabetically).

Can this be done?



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Advanced Filter Macro with InputBox use

You're welcome. The code resizes the selected range to include the cell
above, because an Advanced Filter assumes there's a heading cell.

After extracting the unique values, the fake heading cell is deleted,
then the list is sorted.

Jim May wrote:
Debra:
Thanks so much for the code; I pledge to understand it over the weekend;
Enjoy yours.........
Jim May

"Debra Dalgleish" wrote in message
...

You can use code similar to the following:

'=======================
Sub GetUnique()
Dim rng As Range

If Selection.Columns.Count 1 Then
MsgBox "Please select cells in one column only"
Exit Sub
End If
If Selection.Row = 1 Then
MsgBox "Selection cannot include row 1"
Exit Sub
End If
Set rng = Selection.Offset(-1, 0) _
.Resize(Selection.Rows.Count + 1, 1)

Columns("J:J").Clear
rng.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("J1"), Unique:=True
Range("J1").Delete shift:=xlUp
Range("J1").CurrentRegion.Sort Key1:=Range("J1"), _
Order1:=xlAscending, Header:=xlGuess
End Sub
'==========================

wrote:

I'd like to:

Highlight/Select a range say B5:B25
That contains (bob, carol, ted, ted, bob, alice, carol,
bob, ted, alice, carol......) << only 4 unique names are
in B5:B25 (bob, ted, carol alice)

Then run a macro that will using an Input box (where I
supply a cell reference, like J1 {enter}
and an Advance Filter is run and pastes to Range J1:J4
Alice, Bob, Carol
Ted (alphabetically).

Can this be done?



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html






--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advanced Filter Macro Failing Mustang Excel Discussion (Misc queries) 3 June 18th 09 05:15 AM
Inputbox macro filter using "Contains" Tony S.[_2_] Excel Discussion (Misc queries) 4 July 18th 08 02:02 PM
Advanced Filter Macro Alex.W Excel Discussion (Misc queries) 1 April 4th 08 12:19 PM
Advanced Filter Macro Dolphinv4 Excel Discussion (Misc queries) 2 March 20th 08 11:42 AM
VB Application for Advanced filter Macro Poogy Excel Programming 1 August 19th 03 03:37 PM


All times are GMT +1. The time now is 10:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"