哥也色中文娱乐网
丝袜 av VBA助力制造业:出产谋略自动化,物料需求精确掌控!
场景态状:丝袜 av
小周是一家中微型制造企业的出产谋略员,清晰制定出产谋略和物料需求谋略。他需要阐发客户的订单来详情出产任务,并确保有裕如的原材料来完成这些任务。由于家具种类较多,何况出产过程中还波及到多个工序,因此手工编制出产谋略和物料需求表绝顶繁琐且容易出错。为了擢升效果并减少虚伪,小周决定使用VBA来自动化这些任务。
示例表格数据:
出产订单表:
插插综合物料清单表(BOM):
库存表:丝袜 av
相应的VBA代码:
Sub AutomateProductionPlanningAndMRP() Dim wsOrders As Worksheet Set wsOrders = ThisWorkbook.Sheets("出产订单表") Dim wsBOM As Worksheet Set wsBOM = ThisWorkbook.Sheets("物料清单表") Dim wsInventory As Worksheet Set wsInventory = ThisWorkbook.Sheets("库存表") ' 得回出产订单表的临了一滑 Dim lastRowOrders As Long lastRowOrders = wsOrders.Cells(wsOrders.Rows.Count, "A").End(xlUp).Row ' 得回物料清单表的临了一滑 Dim lastRowBOM As Long lastRowBOM = wsBOM.Cells(wsBOM.Rows.Count, "A").End(xlUp).Row ' 得回库存表的临了一滑 Dim lastRowInventory As Long lastRowInventory = wsInventory.Cells(wsInventory.Rows.Count, "A").End(xlUp).Row ' 创建新的使命表来记载物料需求谋略 Dim wsMRP As Worksheet Set wsMRP = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)) wsMRP.Name = "物料需求谋略" ' 写入表头 wsMRP.Cells(1, 1).Value = "家具编号" wsMRP.Cells(1, 2).Value = "物料编号" wsMRP.Cells(1, 3).Value = "物料称呼" wsMRP.Cells(1, 4).Value = "单元" wsMRP.Cells(1, 5).Value = "单件用量" wsMRP.Cells(1, 6).Value = "总用量" wsMRP.Cells(1, 7).Value = "现时库存" wsMRP.Cells(1, 8).Value = "安全库存" wsMRP.Cells(1, 9).Value = "最大库存" wsMRP.Cells(1, 10).Value = "需求数目" wsMRP.Cells(1, 11).Value = "提倡补货数目" ' 启动化行计数器 Dim processedRow As Long processedRow = 2 ' 创建一个字典来存储物料确现时库存 Dim inventoryLevels As Object Set inventoryLevels = CreateObject("Scripting.Dictionary") ' 启动化库存水平 For i = 2 To lastRowInventory Dim materialID As String Dim currentStock As Long Dim safetyStock As Long Dim maxStock As Long materialID = wsInventory.Cells(i, 1).Value currentStock = wsInventory.Cells(i, 3).Value safetyStock = wsInventory.Cells(i, 4).Value maxStock = wsInventory.Cells(i, 5).Value inventoryLevels.Add materialID, currentStock Next i ' 遍历出产订单表中的每一滑 For i = 2 To lastRowOrders Dim orderID As String Dim productID As String Dim orderQty As Long Dim completedQty As Long Dim orderStatus As String Dim deliveryDate As Date orderID = wsOrders.Cells(i, 1).Value productID = wsOrders.Cells(i, 2).Value orderQty = wsOrders.Cells(i, 3).Value completedQty = wsOrders.Cells(i, 4).Value orderStatus = wsOrders.Cells(i, 5).Value deliveryDate = wsOrders.Cells(i, 6).Value ' 遍历物料清单表中的每一滑 For j = 2 To lastRowBOM Dim bomProductID As String Dim materialID As String Dim materialName As String Dim unit As String Dim singlePieceUsage As Long Dim totalUsage As Long bomProductID = wsBOM.Cells(j, 1).Value materialID = wsBOM.Cells(j, 2).Value materialName = wsBOM.Cells(j, 3).Value unit = wsBOM.Cells(j, 4).Value singlePieceUsage = wsBOM.Cells(j, 5).Value totalUsage = wsBOM.Cells(j, 6).Value If bomProductID = productID Then Dim currentStock As Long currentStock = inventoryLevels(materialID) Dim requiredQty As Long requiredQty = (orderQty - completedQty) * singlePieceUsage Dim suggestedReorderQty As Long suggestedReorderQty = IIf(currentStock < requiredQty, requiredQty - currentStock, 0) ' 将处理适度写入新的使命表 wsMRP.Cells(processedRow, 1).Value = productID wsMRP.Cells(processedRow, 2).Value = materialID wsMRP.Cells(processedRow, 3).Value = materialName wsMRP.Cells(processedRow, 4).Value = unit wsMRP.Cells(processedRow, 5).Value = singlePieceUsage wsMRP.Cells(processedRow, 6).Value = totalUsage wsMRP.Cells(processedRow, 7).Value = currentStock wsMRP.Cells(processedRow, 8).Value = inventoryLevels(materialID + "_safety") wsMRP.Cells(processedRow, 9).Value = inventoryLevels(materialID + "_max") wsMRP.Cells(processedRow, 10).Value = requiredQty wsMRP.Cells(processedRow, 11).Value = suggestedReorderQty ' 出动到下一滑 processedRow = processedRow + 1 End If Next j Next iEnd Sub
VBA代码逐行评释注解:
启动化wsOrders为现时使命簿中的“出产订单表”使命表对象。启动化wsBOM为现时使命簿中的“物料清单表”使命表对象。启动化wsInventory为现时使命簿中的“库存表”使命表对象。得回出产订单表、物料清单表和库存表的临了一滑,以便知谈有若干数据需要处理。创建新的使命表wsMRP用来记载物料需求谋略。修复新使命表的表头信息。启动化行计数器processedRow用于记载物料需求谋略表中的行。创建一个字典inventoryLevels来存储物料确现时库存、安全库存和最大库存。启动化库存水平。遍历出产订单表中的每一滑,查验物料清单并料想需求数目。若是物料清单对应的家具编号与订单表中的家具编号相匹配,则料想所需物料的数目。将处理适度写入新的使命表中。
不错拓展的标的:
添加邮件或短信辅导功能,当库存低于安全库存量时自动见告采购部门。与ERP系统集成,杀青数据的及时同步和更新。使用图表展示库存景况,使库存处置愈加直不雅。与供应商处置系统集成,杀青自动化的补货历程。引入机器学习算法估量物料需求,优化库存处置政策。
和蔼我:
若是你但愿了解如何通过VBA来简化出产谋略和物料需求谋略,并需要匡助编写特定的VBA剧蓝本安妥你的业务需求,请随时联系我,我会为你提供专科的复旧和匡助。
#讲授创作激发谋略#丝袜 av