在1工作簿中的多个Excel工作表(dynamic行数)的VBAsearch和比较代码

我有12个工作表(每个月1)中包含未知数量的条目(行)。 这些行跟踪交付数据。 我想parsing每一行的每一页,并执行以下操作:

计算从A到B的交货数量。计算从A到B的件数。计算从A到B的交货成本。计算从A到B的总货物重量。

这些理货需要被输出到总结工作表,并且需要每月和年度至今。

示例列和单个数据行如下所示:

Date&Time PU | Date&Time Del |PU Loc. Name |PU Street |PUCityStateZip |DEL Loc. Name|DEL Street |DELCityStateZip |Number of Pieces|Weight |TotalAmt 01/01/2016 05:30 | 01/01/2016 07:30 | Warehouse A | 123 Nowhere St. | Toronto, ON P3L 3M0 | Hospital A | 321 Made-up Ave. | Stratford, ON T45 6H8 | 6 | 240 Lbs | $245.00 02/01/2016 06:30 | 02/01/2016 07:30 | Warehouse B | 123 Lost Road | Hamilton, ON P3X 3Z0| Hospital A | 321 Made-up Ave. | Stratford, ON T4P 6H8 | 3 | 240 Lbs | $245.00 01/01/2016 09:30 | 02/01/2016 11:30 | Warehouse A | 123 Nowhere St. | Toronto, ON P3L 3M0 | Hospital B | 123 Boul Fake. | Montreal, QC T4Y 6J8 | 1 | 24 Lbs | $45.00 04/01/2016 05:30 | 04/01/2016 07:30 | Warehouse A | 123 Nowhere St. | Toronto, ON P3L 3M0 | Hospital A | 321 Made-up Ave. | Stratford, ON T4P 6H8 | 4 | 160 Lbs | $145.00 Using the sample data above we would have(for total number of deliveries): 2 Deliveries from Warehouse A to Hospital A 1 Delivery from Warehouse B to Hospital A 1 Delivery from Warehouse A to Hospital B 

我知道如何通过不同的工作表循环。 我也知道如何循环到最后一行的末尾,行数未知。

我不知道sorting我的数据,比较接送地点的最佳方法。 即。 我需要查看数据,以确定A仓库在一月份交付了7次,在2月份交付了15次,在12月份交付了10次。我没有代码完成这项工作,在这一点上,因为我有问题想象如何最好地处理这个问题。

这必须是一个VBA解决scheme – 我以前可以用手工完成,但是我想要一个“自动”的VBA解决scheme。

任何援助表示赞赏。

您可以使用以下SQL语句打开logging集:

 SELECT Year([Date&Time Del]), Month([Date&Time Del]), [PU Loc. Name], [DEL Loc. Name] COUNT(*) AS CountOfDeliveries FROM [SheetName$] GROUP BY Year([Date&Time Del]), Month([Date&Time Del]), [PU Loc. Name], [DEL Loc. Name] 

并使用CopyRecordset将结果粘贴到输出工作表中。

如果你想按年份而不是按月份(这个问题不太清楚),使用下面的SQL语句:

 SELECT Year([Date&Time Del]), [PU Loc. Name], [DEL Loc. Name] COUNT(*) AS CountOfDeliveries FROM [SheetName$] GROUP BY Year([Date&Time Del]), [PU Loc. Name], [DEL Loc. Name] 

在这里看到类似的东西。