有哪些 VBA 代码选项可将数据分组到时间段中、将其复制到另一张表并循环多个部分(标准)
我有两个文件: 文件#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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您可以使用 SUMPRODUCT 公式来将这些数字带入而无需代码。此示例在同一工作簿中使用两个工作表,因此您必须针对不同的工作簿稍微进行调整。在 Sheet1 中,您有三个范围,我将其命名为 rngPartNum、rngDemandDate 和 rngDemandQty。我使用了随数据扩展的动态范围名称,但您可以使用覆盖足够行数的单元格引用。数据看起来像
Sheet2 每行都有一个周末日期和一个零件编号。
需求列中的公式如下:
对 rngDemandQty 中的所有内容求和,其中 rngPartNum 与 A2 匹配并且 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
Sheet2 has a week-end date and a part number on each row.
The formula in the demand column is this
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.