Advanced filter criterion loop for querying Excel database

marrick13

New Member
Joined
Oct 7, 2005
Messages
14
I have a userform and database for entering food purchases by receipt. The database is arranged with its first few left columns containing date information for each receipt, with the other columns representing the food items and their costs. There are over 140 such food item columns.

I am building different queries to show the expense totals by item, month, month and item, year, etc., in 3-row columns for display purposes, such as these (partial examples):

Item: Berries
Month Year Expense
Jan 2012 $ 12.36
Feb 2012 $ 7.89
Mar 2012 $ 9.12

And this:

Item: Berries
Month Year Expense
Apr 1999 $ 15.40
Apr 2000 $ 10.75
Apr 2001 $ 13.56
Apr 2002 $ 14.78

I am using advanced filter to extract chunks of unsummarized data, and DSUM formulas to produce totals from this extract to show costs in the above formats. The tricky part is those queries showing costs for the same month for each year, because I then need all the years in the database (1999-2012). I am trying to avoid setting up a criterion section with the item, month and year, and deciding what to do when a new year starts up (I already have 12 criterion sections for the months, but those will never exceed 12). So I am thinking of having one criterion section, extracting the unique years from the database, perhaps into an array, and then looping through those years, putting each year into the Year criterion field, calculating the result, and then storing that result so the next year doesn’t affect the previous year’s total (such a technique could also be used for the months, so I won’t need 12 criterion sections). At least this way, I can do with a single criterion section, no matter how many years get appended to the database.

Not that I know exactly how to do this looping, but is this a good approach, or is there a better way to achieve such query results?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Thanks, Marcelo. I did consider a pivot table, but found it too awkward. Don't forget, I have over 140 food items, and I need to include them all for some queries. I did try a manual pivot and didn't like how it was forming when checking off those items. I thought the advanced filter-DSUM combo was the better option.

Even if a pivot table was the better option, I would need it to be created through VBA, and since I didn't have much luck creating one for this database manually, I don't think I'd have much luck creating one in VBA.
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top