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
555 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 23

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

: 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…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

615 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