[VBA] Average number of days between dates for multiple entries in PivotCache

Cornerback

New Member
Joined
Mar 20, 2013
Messages
4
Hi everybody,

my current task is to evaluate data from a MSSQL-DB. This is done by creating a pivot cache, from which pivot charts are generated. This works fine ;)

Every DB-entry has a field with a start date and a field with a end-date. My task is to get the number of days between those two dates for EVERY entry in the DB and then calculate the average of those days. (the entries are selected by entering the start- and end-date in a userform, if this does matter...)

Any ideas how to do this in VBA?

kind regards

Cornerback
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If you have the Start Date in Column A and the End Date in column B, then you can use the next VBA statement:
avg = [SUM(B2:B10000-A2:A10000)/COUNT(A2:A10000)]
 
Upvote 0
Okay, doing it with a temporary table sound reasonable. Thanks :)

is there, however, any way to calculate those values directly from the PivotCache or from the MSSQL-Table without writing them into a excel-sheet first?
 
Upvote 0

Forum statistics

Threads
1,215,576
Messages
6,125,633
Members
449,242
Latest member
Mari_mariou

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