Solved

Macro to sum data in a column based on values in 2 other columns, while counting the number of cells on which each sum is based

Posted on 2014-10-20
1
548 Views
Last Modified: 2014-10-21
Hi,

I am looking for a macro that sums the values in a column based on a date and an ID, while counting the number of values that were summed for each date and ID.

I have attached some Sample Data, along with a (partial) screenshot (Sample Data Screenshot 1) with which to explain the problem. The screenshot is based on rows 1-33 from Sheet 3 of the Sample Data spreadsheet.
The data is ordered based on the initial date and time of each row (in columns A and B) and also based on an ID (in column E).

For a given date and a given ID, the values in column P, labelled “Dist”, need to be summed, while counting the number of values that were summed for each date and for each ID.

Using the screenshot as an example, rows 2-12 are on 29/11/2012 with the ID of IV4; rows 13-22 are on 30/11/2012 with the ID of IV4; and rows 23-33 are on 1/11/2012 with the ID of IV5. As long as the date in column A and the ID in column E are the same (i.e. before moving to a new date or ID), the values in column P need to be summed, and the number of values on which each sum is based need to be counted.

All other data in all other columns can be ignored/deleted.

For the output from the macro, for rows 2-12 this would be a sum of 55.58 and a count of 8; for rows 13-22 this would be a sum of 66.43 and a count of 8; and for rows 23-33 this would be a sum of 36.84 and a count of 11.

I anticipate that for each date and each ID the values in column P could be summed into the first row of each date and ID, and the subsequent rows could be deleted, with perhaps the count data going in column W (the first empty column). I have attached an additional screenshot (Sample Data Screenshot 2) of what I think the resultant dataset may look like.

Additionally, for the count data, there are only entries in column P when the value in column F is “T” (rather than “C”), and as such the counts should not take account of blank cells in column P. The dataset covers approximately 3 years of data.

Any help with making this macro is much appreciated and thanks in advance.
Sample-Data.xlsx
Sample-Data-Screenshot-1.jpg
Sample-Data-Screenshot-2.jpg
0
Comment
Question by:Peter Weldon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
Ejgil Hedegaard earned 500 total points
ID: 40392884
You don't need a macro, use the formulas sumifs and countifs, see sheet3, columns X to AA.
Sample-Data.xlsx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question