有哪些 VBA 代码选项可将数据分组到时间段中、将其复制到另一张表并循环多个部分(标准)

发布于 2024-10-27 03:00:09 字数 318 浏览 0 评论 0原文

我有两个文件: 文件#1 包含客户的需求信息。只有三列对我来说很重要:
部分# 需求数量 要求日期 该文件有数千行。

File#2 是我自己的文件,其中包含更多 MRP 设置: 列标有日期(每周) 对于每个部分:有以下行: 要求 进货库存 净库存

我的总体想法是,我可以以某种方式按零件编号过滤这两个文件,然后使用代码“sumif”按周计算总需求,并将其从客户文件复制到我的文件中相应的需求行。然后对所有部件循环此操作。

在我的电子表格中不断添加/删除零件(随着新项目的开发和旧项目的逐步淘汰),因此如果在我的文件更新为新零件时不需要维护代码,那将是理想的选择。

I have two files:
File#1 contains customer with demand information. There are only three columns that matter to me:
Part#
Demand Qty
Demand Date
The file has thousands of lines.

File#2 is my own file which has more of an MRP setup:
columns are labeled with dates (weekly)
For each Part: There are the following rows:
Demand
Incoming Inventory
Net Inventory

My general idea was that I could somehow filter both files by part#, then have the code "sumif" the total demand by week, and copy it from the customer file to my file on the corresponding demand row. Then loop this for all part #s.

Part #s are constantly being added/removed in my spreadsheet(as new projects develop, and old ones phase out), so it would be ideal if the code didnt need to be maintenenced as my file is updated with new parts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我乃一代侩神 2024-11-03 03:00:09

似乎您可以使用 SUMPRODUCT 公式来将这些数字带入而无需代码。此示例在同一工作簿中使用两个工作表,因此您必须针对不同的工作簿稍微进行调整。在 Sheet1 中,您有三个范围,我将其命名为 rngPartNum、rngDemandDate 和 rngDemandQty。我使用了随数据扩展的动态范围名称,但您可以使用覆盖足够行数的单元格引用。数据看起来像

PartNum Demand Qty  DemandDate
1           18          3/28/2011
1           6           3/30/2011
1           6           4/2/2011
2           18          3/28/2011
2           6           3/30/2011
2           6           4/2/2011
2           16          3/28/2011
3           3           3/30/2011
3           15          4/2/2011
3           9           3/28/2011
3           18          3/30/2011

Sheet2 每行都有一个周末日期和一个零件编号。

Part    Week       Demand
1       4/1/2011    24
1       4/8/2011    6
1       4/15/2011   0
2       4/1/2011    40
2       4/8/2011    6
2       4/15/2011   0
3       4/1/2011    30
3       4/8/2011    15
3       4/15/2011   0

需求列中的公式如下:

=SUMPRODUCT((rngPartNum=A2)*(rngDemandDate<=B2)*(rngDemandDate>B2-7)*(rngDemandQty))

对 rngDemandQty 中的所有内容求和,其中 rngPartNum 与 A​​2 匹配并且 rngDemandDate 小于或等于 B2 并且 rngDemandDate 大于 B2 之前一周。只要 Sheet2 上有每个零件号和足够的周数,总数就应该与 Sheet1 相符。

It seems like you could use a SUMPRODUCT formula to bring those numbers in without code. This example uses two sheets in the same workbook so you'd have to adjust slightly for different workbooks. In Sheet1 you have three ranges which I've named rngPartNum, rngDemandDate, and rngDemandQty. I used dynamic range names that expand with the data, but you could use cell references that cover a sufficient number of rows. The data looks like this

PartNum Demand Qty  DemandDate
1           18          3/28/2011
1           6           3/30/2011
1           6           4/2/2011
2           18          3/28/2011
2           6           3/30/2011
2           6           4/2/2011
2           16          3/28/2011
3           3           3/30/2011
3           15          4/2/2011
3           9           3/28/2011
3           18          3/30/2011

Sheet2 has a week-end date and a part number on each row.

Part    Week       Demand
1       4/1/2011    24
1       4/8/2011    6
1       4/15/2011   0
2       4/1/2011    40
2       4/8/2011    6
2       4/15/2011   0
3       4/1/2011    30
3       4/8/2011    15
3       4/15/2011   0

The formula in the demand column is this

=SUMPRODUCT((rngPartNum=A2)*(rngDemandDate<=B2)*(rngDemandDate>B2-7)*(rngDemandQty))

That sums everything in rngDemandQty where rngPartNum matches A2 AND rngDemandDate is less than or equal to B2 AND rngDemandDate is greater than a week before B2. As long as you have every part number and enough weeks on your Sheet2, the total should match Sheet1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文