LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Advanced Filter problems using VBA in XL2007

On May 7, 5:12 pm, Tom Hutchins
wrote:
This might the problem...

Using the advanced filter creates the range names Criteria, Extract, and
_FilterDatabase (which is hidden) in the workbook, to keep track of the
previous Advanced Filter range specifications. If not deleted, they will keep
the macro from successfully running the advanced filter again. You are
creating the ranges when you record yourself performing the filter.

Here is a macro I have used to delete these ranges. Call it before
re-running your advanced filter.

Sub DelRngNames()
On Error Resume Next
ActiveWorkbook.Names(ShtName$ & "!Criteria").Delete
ActiveWorkbook.Names(ShtName$ & "!Extract").Delete
ActiveWorkbook.Names(ShtName$ & "!_FilterDatabase").Delete
End Sub

Replace ShtName$ with the name of the worksheet where the advanced filter
will be applied.

Hope this helps,

Hutch

" wrote:
I used to think I was OK in VBA, but now I'm not so sure ...


I have a sheet within which I have a list linked to a MOSS list.
(The file was created in XL2003 and I'm using XL2007, so the
synchronization functionality is working just fine)


I have another sheet on which I wish to filter selected records from
the MOSS-linked list.


The following code is called from the 'receiving' sheet:
Sub Advanced_Filter_Due_To_Complete_Projects()
Sheets("Projects Due For Completion").Activate
Range("H2").Value = "=" &
Format(Range("To_Complete_Date_1").Value,"dd/mm/yyyy")
Range("I2").Value = "<=" &
Format(Range("To_Complete_Date_2").Value,"dd/mm/yyyy")
ActiveSheet.Range(Range("B5").End(xlDown),
Range("B5").End(xlToRight).Offset(1, 0)).ClearContents
Range("'MOSS Projects In Progress'!
Projects_In_Progress").AdvancedFilter Action:= _
xlFilterCopy, CriteriaRange:=Range("H1:I2"),
CopyToRange:=Range("B5:E5"), Unique:=False
End Sub


The 'destination' sheet is 'Projects Due For Completion'
The 'source' sheet is 'MOSS Projects In Progress'
The MOSS-linked list is named 'Projects_In_Progress'.


If I record a macro whilst performing the filter, obviously everything
works just fine. Running the code afterwards though produces no result
at all.
I've tried qualifying the ranges in a variety of different ways
(sheets(...).range(...), range(...) etc.), but no joy.
I've also changed the criteria from being calculated as a formula to
being created as a string value and entered (as in the code above). I
read on another thread that it may be something to do with string
manipulation of date fields by XL? (the format on the source sheet
list is 'dd/mm/yyyy' as in the code above)


I can only guess as to why its not working - maybe something to do
with the list/'name' in XL2007? I have tried creating a dynamic range
name for the list "MOSS_Projects_In_Progress" referring to the list
just in case that's it, but that doesn't work either.


Basically, I'm stumped and can't see the solution. No doubt its
something obvious and I'll kick myself once its pointed out to me.


Can anyone help shed any light on this please?


Thanks,


Rob


Thanks for the response.

Alas, your suggestion didn't work. I've removed all the 'criteria'
and 'extract' range names from the workbook manually, and run this
extra code also, but still no joy. I have another 5 or 6 advanced
filters that run just fine, but there are 2 (same code, just different
filter criteria) that don't work. They both have 'date' criteria
where the other filters (that all do work) are just simple 'text'
criteria (i.e. where 'colour' = 'red').

Hence one of my thoughts that it could be something to do with the
'date' comparison criteria - perhaps the string needs to be
constructed differently when running an advanced filter through VBA
compared to the normal XL interface.

I'll keep looking, but any other hints/tips etc. much appreciated

Rob
 
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
XL2007: Pivot table date filter Scott Williams Excel Discussion (Misc queries) 1 May 29th 09 12:47 PM
Problems implementing advanced filter code... jarviscars Excel Programming 7 January 5th 06 03:06 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 Problems Brian Excel Discussion (Misc queries) 2 December 20th 04 06:31 PM
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 06:17 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"