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
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
546 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
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.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

861 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