Use VBA to Add Values Based on Multiple Criterias

sanj_edu

New Member
Joined
Dec 12, 2017
Messages
11
Hello,
I need to extract a summary from a large data set (I have mentioned an example).

The summary should add up the hours based on location, date and service. Some of the services are to be combined, in the example, you will notice that the hours for Domestic RRD and CTL RRD are added together for the same location and date.

Any help would be appreciated!
Thank you!


LocationDateServiceHours
TYC12/1/2017Domestic RRD 2
TYC12/1/2017INTL RRD7
TYC12/2/2017Domestic RRD 2.5
TYC12/2/2017CTL RRD0.75
CAS12/1/2017Domestic RRD 3.5
CAS12/2/2017INTL RRD9.5
CAS12/2/2017Domestic RRD 1
CAS12/2/2017CTL RRD1.25

<tbody>
</tbody><colgroup><col><col><col><col></colgroup>



Output:Should be on next sheet
LocationDateServiceHours
TYC12/1/2017Domestic 2
TYC12/2/2017Domestic 3.25
TYC12/1/2017INTL7
CAS12/1/2017Domestic 3.5
CAS12/2/2017INTL9.5
CAS12/2/2017Domestic 2.25

<tbody>
</tbody><colgroup><col><col><col><col></colgroup>
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I suppose the elegant solution would be to create a class with a property for each column that utilizes a 2D array to build the summary table.

You could copy the table to the summary location and just loop through to make the changes necessary to condense to a summary.

Another option might be to have the macro to generate the table between 2 given dates and just use a COUNTIFS function to sum the hours.

The last option I can think of would be to skip the macro altogether, use "=LEFT(C2,LEN(C2)-4)" to remove the "RRD"s, replace all "CTL" with "Domestic", and use a pivot table to summarize, then copy/paste.
 
Upvote 0
It appears that you have Cross-Posted this here: https://chandoo.org/forum/threads/u...ased-on-multiple-criterias.36725/#post-220461
and many other places (as denoted in that link).

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,215,598
Messages
6,125,748
Members
449,258
Latest member
hdfarid

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