简体   繁体   English

使用Excel VBA计算另一列中每个日期的一列中的类型计数

[英]Calculate count of type in one column for each date in other column using Excel VBA

I am trying a macro to give me count of columnA containing type of elements per date in columnB. 我正在尝试给我一个宏,以使我计数columnA,其中包含columnB中每个日期的元素类型。 I need to multiply each type count with certain value(volume calculation) and keep total per type per date in new sheet. 我需要将每种类型的计数乘以一定的值(体积计算),并将每种日期的每种类型的总数保持在新表中。

Sample data: 样本数据:

Large        12/12/2016  
Large        12/12/2016
Medium       12/12/2016
Medium       12/12/2016
Medium       12/12/2016
Medium       12/12/2016
Medium       12/12/2016
Medium       12/12/2016    
Medium       12/12/2016
Small        12/12/2016
Large        12/12/2016
Extra Large  12/12/2016
Extra Large  12/12/2016
Extra Large  12/12/2016

Here is my thought process for algorithm. 这是我对算法的思考过程。

  1. Loop each row and try to group dates and find count of each date and paste it in new cell and replace if same date is found again. 循环每一行,尝试对日期进行分组并找到每个日期的计数,然后将其粘贴到新的单元格中,如果再次找到相同的日期,则将其替换。

  2. Loop from min date to max date. 从最小日期到最大日期循环播放。 Fetch all rows for current date and find count of them and place it in new sheet for each date 取得当前日期的所有行并找到它们的计数,然后将其放置在每个日期的新表中

Is this doable using any of the above? 使用以上任何方法可以做到吗? If not can some one help me with new algorithm possible pseudo code. 如果不是的话,有人可以帮助我解决新算法的伪代码。 Please ignore if you feel naive. 如果您感到天真,请忽略。

Here is the pivot table that made with your sample data. 这是使用示例数据制作的数据透视表。 Also, I made a video so you can see how to create it. 另外,我制作了一个视频,以便您了解如何创建它。 With more data you can see you can do much more stuff. 有了更多的数据,您可以看到您可以做更多的事情。 If this is what you were looking for, please hit the checkmark next to this answer to mark it. 如果这是您要查找的内容,请选中此答案旁边的对勾以标记它。

File: 文件:

http://www.filedropper.com/pivot http://www.filedropper.com/pivot

Video: 视频:

https://www.screencast.com/t/BJBUIJPu76 https://www.screencast.com/t/BJBUIJPu76

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM