PHibbert,
Quite honestly, I "shudder" every time I see the "great lengths" Excel users go to in order to perform "filtering" operations such as those described above.
With all due respect, I'm totally convinced that once users appreciate how "easy" it is to set up "criteria" on a SEPARATE sheet, they will begin to use this method, and be TOTALLY SOLD on it.
A little "background info" on this... Microsoft has provided relatively little help on this subject, and furthermore, has failed to eliminate a couple of related BUGS.
One BUG informs the user that it's NOT possible to place criteria on a SEPARATE sheet. NOT True. It IS possible. And not only is it possible, it is "preferable". Placing criteria on the SAME sheet as the database (which Microsoft says is required) causes CONSIDERABLE problems - and both frustrates users and prevents them from creating dynamic and complex criteria.
When I speak of "complex", it's not complex to create the criteria, but complex in terms of the ability to isolate data in the database based on elaborate criteria when required. Examples of criteria that could ALL be part of a "compound" condition are: by Year, Month, Group, Region, City, Department, Employee, Sales, Expenditures, etc.
The other BUG says it's NOT possible to extract records to a SEPARATE sheet. This is "true" IF one attempts to use the Menu method (Data - Filter - Advanced Filter). Ironically, it is the ERROR message itself that "stops you in your tracks". Using VBA, there is NO problem.
By placing the criteria on a SEPARATE sheet, it enables one to create VERY complex formulas - VERY easily. And these criteria can be used interactively with VBA and user-input.
Another "odd" situation that has probably caused some Excel users to get "frightened off" from creating criteria, is when creating a formula for the criteria. When the formula references one of the field names in the database, the formula will return #NAME?. In earlier versions of Excel, I can't recall ever seeing an explanation for the #NAME?, but in later versions like Excel 2000, there is an explanatin to be found IF you look hard enough. It says the #NAME? is "normal" when used as part of a criteria.
Criteria can easily be created to glean whatever data is necessary from the database. The criteria can also reference common cells in the workbook. For example, it is common practice for me to set up applications where all the user has to do to convert a workbook to a "new year", is to simply enter one number in one cell - the number of course being the year. The formulas in the criteria then are "automatically" set for the new year.
If a database has data for more than one year, all the user has to do, again, is to enter just the year, and the criteria will automatically reference that different year.
There is the option to: 1) filter-in-place, or 2) to extract the records to a SEPARATE sheet (using VBA). If a user wants to isolate the data in either of these ways, it can be made as simple as entering the number of the month in a cell and then clicking a macro-button.
Keep in mind, too, that in addition to being able to filter records in place or to extract them, it's also possible to use the SAME criteria to create "summary" reports using Excel's database "formulas" - e.g. =DSUM, =DCOUNTA, =DMAX, =DMIN =DAVERAGE, etc.
One last point on the use of the database formulas and filtering... This option is CONSIDERABLY FASTER than "looping through records" using VBA. The reason is because the database functions are "custom" functions and as such are executed using the "C" programming language - a MUCH faster language than VBA.
I hope this helps you (and other readers) in better understanding and appreciating the SIGNIFICANT power of Excel's "database functionality".
If you'd like help with the particular task at hand, I'd be pleased to help out. The best approach would be for you to email me your file. I'll then modify and return it. The result will serve as a solution, and an example that will likely cause you to have a MUCH better appreciation and understanding of this component of Excel. If you happen to have sensitive data in your file, perhaps you could replace it with fictitious data that still reflects the type of data you're working with.
Regards, ...Dale Watson dwatson@bsi.gov.mb.ca