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
522 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
1 Comment
 
LVL 21

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now