Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default programmatic advanced filter


hi all,

im a lil new to excel automation so forgive me if this is a little easy
for you all.

i have been using an advanced filter which requires the following

input range
input criteria
output range <or location

i need to automate this as I am finding that many people just cant
grasp the advanced filter for reasons which elude me.

anyway Im very familiar with vbs and vb just not at all familiar with
vba.

any thoughts on where to start looking.


--
jmcfadyen
------------------------------------------------------------------------
jmcfadyen's Profile: http://www.excelforum.com/member.php...o&userid=34733
View this thread: http://www.excelforum.com/showthread...hreadid=544956

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default programmatic advanced filter

Hi J,

Try turning on the macro recorder while you perform the requisite steps
manually.
This will provide you with base code which can be rdited to enable more
general application.

If you experiene problems with such editing, post back with rhe problematic
code.


---
Regards,
Norman


"jmcfadyen" wrote
in message ...

hi all,

im a lil new to excel automation so forgive me if this is a little easy
for you all.

i have been using an advanced filter which requires the following

input range
input criteria
output range <or location

i need to automate this as I am finding that many people just cant
grasp the advanced filter for reasons which elude me.

anyway Im very familiar with vbs and vb just not at all familiar with
vba.

any thoughts on where to start looking.


--
jmcfadyen
------------------------------------------------------------------------
jmcfadyen's Profile:
http://www.excelforum.com/member.php...o&userid=34733
View this thread: http://www.excelforum.com/showthread...hreadid=544956



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default programmatic advanced filter

Hi
I use this to do a filter when I have three or more items to filter on
in one column. you may be able to adapt it for your filter.
I'm assuming the user is selecting multiple items in a listbox called
Grouplistdata. The count of the selected items is Groupcount.
I've added a sub at the end which I use to add sheets.

CODE SNIPPET:
'Remove any filter present on the sheet
With Worksheets("Test")
On Error Resume Next 'required if Advanced filter used
.ShowAllData
On Error GoTo 0
.AutoFilterMode = False 'Removes drop down arrows
End With
Select Case GroupCount 'a listbox selection count
'Check the user hasn't clicked OK on the userform without selecting
anything
Case 0
Exit Sub 'nothing happens and form is still visible
'Use AutoFilter if GroupCount is 1 or 2
Case 1
GroupRange.AutoFilter Field:=1,
Criteria1:=CStr(Grouplistdata(1))
Case 2
GroupRange.AutoFilter Field:=1,
Criteria1:=CStr(Grouplistdata(1)), Operator:=xlOr, _
Criteria2:=CStr(Grouplistdata(2))
Case Is 2
'Start by inserting a worksheet and creating a Criteria Range to put
into AdvancedFilter
'addSheet first removes the sheet, so it is always a fresh sheet
AddSheet "WorkSpaceSheet" 'now the active sheet
With ActiveWorkbook.Worksheets("WorkSpaceSheet")
.Visible = False
.Cells(1, 1).Value = "Group" 'same as name on worksheet
"Test"
i = 1 'set a counter and put group items below "Group"
For Each Item In Grouplistdata
i = i + 1
.Cells(i, 1).Value = Item
Next Item

Set GroupCriteria = .Cells(1, 1).CurrentRegion
End With 'worksheet
'Filter the list
Worksheets("Test").Activate
GroupRange.AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:=GroupCriteria
End Select

END CODE SNIPPET

Public Sub AddSheet(TheSheetName As String)
Dim wsNew As Worksheet 'we will insert a fresh worksheet
With ActiveWorkbook
On Error Resume Next
Application.DisplayAlerts = False
.Worksheets(TheSheetName).Delete
On Error GoTo 0
Application.DisplayAlerts = True
'If worksheet is not there the error in deletion is ignored
'Add a new sheet
Set wsNew = .Worksheets.Add 'Makes wsNew the active sheet
wsNew.Name = TheSheetName
End With
Set wsNew = Nothing
End Sub

regards
Paul

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
export filter - programmatic access to Peter Charts and Charting in Excel 0 October 28th 08 10:43 PM
Why won't advanced filter return filter results? jaws4518 Excel Worksheet Functions 5 September 12th 06 06:11 PM
How do I use advanced filter to filter for blank cells? Monique Excel Discussion (Misc queries) 2 March 21st 06 06:43 PM
"Criteria Range" in the "Data/Filter/Advanced Filter" to select Du TC Excel Worksheet Functions 1 May 12th 05 02:06 AM
advanced filter won't allow me to filter on bracketed text (-456.2 LucianoG Excel Discussion (Misc queries) 1 December 6th 04 08:38 PM


All times are GMT +1. The time now is 12:48 PM.

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

About Us

"It's about Microsoft Excel"