Files
server-configs/siyuan/data/20250828093252-n67vyhm/20250907234816-e42fwgq/20250917131608-itdo73m.sy
2026-02-13 22:24:27 +08:00

1 line
51 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"ID":"20250917131608-itdo73m","Spec":"2","Type":"NodeDocument","Properties":{"id":"20250917131608-itdo73m","title":"VBA函数_介绍","type":"doc","updated":"20250922082941"},"Children":[{"ID":"20250917132120-kfj50oj","Type":"NodeParagraph","Properties":{"id":"20250917132120-kfj50oj","updated":"20250917132157"},"Children":[{"Type":"NodeText","Data":"A依次运行BCD"}]},{"ID":"20250917132120-kfa2f60","Type":"NodeCodeBlock","IsFencedCodeBlock":true,"Properties":{"id":"20250917132120-kfa2f60","updated":"20250922082941"},"Children":[{"Type":"NodeCodeBlockFenceOpenMarker","Data":"```"},{"Type":"NodeCodeBlockFenceInfoMarker","CodeBlockInfo":"dmJh"},{"Type":"NodeCodeBlockCode","Data":"Sub A()\n Call B\n Call Q\nEnd Sub\n"},{"Type":"NodeCodeBlockFenceCloseMarker","Data":"```"}]},{"ID":"20250917132117-a1ktaur","Type":"NodeParagraph","Properties":{"id":"20250917132117-a1ktaur","updated":"20250917132117"},"Children":[{"Type":"NodeText","Data":"主逻辑并生成BOM无匹配表"}]},{"ID":"20250917132107-2vgwitg","Type":"NodeCodeBlock","IsFencedCodeBlock":true,"Properties":{"id":"20250917132107-2vgwitg","updated":"20250919095538"},"Children":[{"Type":"NodeCodeBlockFenceOpenMarker","Data":"```"},{"Type":"NodeCodeBlockFenceInfoMarker","CodeBlockInfo":"dmJh"},{"Type":"NodeCodeBlockCode","Data":"Sub B()\n Dim wsFocest As Worksheet, wsBOM As Worksheet, wsOutput As Worksheet, wsUnmatched As Worksheet\n Dim lastRowF As Long, lastRowB As Long, lastRowO As Long, lastRowU As Long\n Dim i As Long, j As Long, k As Long, col As Long\n Dim keyPart As String, material As String, usage As Double\n Dim lic As Double, focestCol1 As String, focestCol2 As String\n Dim weekValues(1 To 56) As Double\n Dim dictBOM As Object, dictUnmatched As Object\n Dim materialData As Variant\n Dim key As Variant\n \n Set dictBOM = CreateObject(\"Scripting.Dictionary\")\n Set dictUnmatched = CreateObject(\"Scripting.Dictionary\")\n \n ' Set worksheets\n Set wsFocest = ThisWorkbook.Sheets(\"Focest\")\n Set wsBOM = ThisWorkbook.Sheets(\"BOM\")\n \n ' Create new worksheets for output\n On Error Resume Next\n Application.DisplayAlerts = False\n ThisWorkbook.Sheets(\"Output\").Delete\n ThisWorkbook.Sheets(\"Unmatched\").Delete\n Application.DisplayAlerts = True\n On Error GoTo 0\n \n Set wsOutput = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))\n wsOutput.Name = \"Output\"\n Set wsUnmatched = ThisWorkbook.Sheets.Add(After:=wsOutput)\n wsUnmatched.Name = \"Unmatched\"\n \n ' Read BOM data into dictionary\n lastRowB = wsBOM.Cells(wsBOM.Rows.Count, \"A\").End(xlUp).Row\n For i = 2 To lastRowB\n keyPart = Trim(wsBOM.Cells(i, 1).Value \u0026 \"\")\n material = Trim(wsBOM.Cells(i, 2).Value \u0026 \"\")\n \n ' 安全处理usage值\n If IsNumeric(wsBOM.Cells(i, 3).Value) Then\n usage = CDbl(wsBOM.Cells(i, 3).Value)\n Else\n usage = 0\n End If\n \n If keyPart \u003c\u003e \"\" And material \u003c\u003e \"\" Then\n If Not dictBOM.Exists(keyPart) Then\n dictBOM.Add keyPart, New Collection\n End If\n dictBOM(keyPart).Add Array(material, usage)\n End If\n Next i\n \n ' Prepare Output header with additional columns\n wsOutput.Cells(1, 1).Value = \"Focest Col1\"\n wsOutput.Cells(1, 2).Value = \"Focest Col2\"\n wsOutput.Cells(1, 3).Value = \"Material Number\"\n wsOutput.Cells(1, 4).Value = \"BOM Usage\"\n For col = 1 To 56\n wsOutput.Cells(1, col + 4).Value = \"Week\" \u0026 col\n Next col\n \n ' Process Focest table\n lastRowF = wsFocest.Cells(wsFocest.Rows.Count, \"A\").End(xlUp).Row\n lastRowO = 1\n \n For i = 2 To lastRowF\n keyPart = Trim(wsFocest.Cells(i, 1).Value \u0026 \"\")\n If keyPart = \"\" Then GoTo NextFocestRow\n \n focestCol1 = wsFocest.Cells(i, 1).Value \u0026 \"\"\n focestCol2 = wsFocest.Cells(i, 2).Value \u0026 \"\"\n \n ' 安全处理LIC值\n If IsNumeric(wsFocest.Cells(i, 2).Value) Then\n lic = CDbl(wsFocest.Cells(i, 2).Value)\n Else\n lic = 0\n End If\n \n ' Extract week values with error handling\n For j = 1 To 56\n If IsNumeric(wsFocest.Cells(i, j + 2).Value) Then\n weekValues(j) = CDbl(wsFocest.Cells(i, j + 2).Value)\n Else\n weekValues(j) = 0\n End If\n Next j\n \n If dictBOM.Exists(keyPart) Then\n For k = 1 To dictBOM(keyPart).Count\n materialData = dictBOM(keyPart)(k)\n material = materialData(0)\n usage = materialData(1)\n lastRowO = lastRowO + 1\n \n wsOutput.Cells(lastRowO, 1).Value = focestCol1\n wsOutput.Cells(lastRowO, 2).Value = focestCol2\n wsOutput.Cells(lastRowO, 3).Value = material\n wsOutput.Cells(lastRowO, 4).Value = usage\n \n For col = 1 To 56\n wsOutput.Cells(lastRowO, col + 4).Value = weekValues(col) * lic * usage\n Next col\n Next k\n Else\n If Not dictUnmatched.Exists(keyPart) Then\n dictUnmatched.Add keyPart, True\n End If\n End If\n \nNextFocestRow:\n Next i\n \n ' Generate unmatched sheet\n lastRowU = 1\n wsUnmatched.Cells(1, 1).Value = \"Unmatched Key Part Numbers\"\n \n For Each key In dictUnmatched.Keys\n lastRowU = lastRowU + 1\n wsUnmatched.Cells(lastRowU, 1).Value = key\n Next key\n \n ' Auto-fit columns\n wsOutput.Columns.AutoFit\n wsUnmatched.Columns.AutoFit\n \n MsgBox \"Processing completed! \" \u0026 lastRowO - 1 \u0026 \" rows generated in Output sheet.\"\nEnd Sub\n"},{"Type":"NodeCodeBlockFenceCloseMarker","Data":"```"}]},{"ID":"20250919095542-0wgxsqv","Type":"NodeParagraph","Properties":{"id":"20250919095542-0wgxsqv","updated":"20250919095736"},"Children":[{"Type":"NodeText","Data":"主逻辑并生成BOM无匹配表 V2.0"}]},{"ID":"20250919095546-rfawfv6","Type":"NodeCodeBlock","IsFencedCodeBlock":true,"Properties":{"id":"20250919095546-rfawfv6","updated":"20250919095828"},"Children":[{"Type":"NodeCodeBlockFenceOpenMarker","Data":"```"},{"Type":"NodeCodeBlockFenceInfoMarker","CodeBlockInfo":"dmJh"},{"Type":"NodeCodeBlockCode","Data":"Sub B()\n Application.ScreenUpdating = False\n Application.Calculation = xlCalculationManual\n Application.EnableEvents = False\n \n Dim wsFocest As Worksheet, wsBOM As Worksheet, wsOutput As Worksheet, wsUnmatched As Worksheet\n Dim lastRowF As Long, lastRowB As Long, lastRowO As Long, lastRowU As Long\n Dim i As Long, j As Long, k As Long, col As Long\n Dim keyPart As String, material As String, usage As Double\n Dim lic As Double, focestCol1 As String, focestCol2 As String\n Dim weekValues(1 To 56) As Double\n Dim dictBOM As Object, dictUnmatched As Object\n Dim materialData As Variant\n Dim key As Variant\n \n Set dictBOM = CreateObject(\"Scripting.Dictionary\")\n Set dictUnmatched = CreateObject(\"Scripting.Dictionary\")\n \n ' Set worksheets\n Set wsFocest = ThisWorkbook.Sheets(\"Focest\")\n Set wsBOM = ThisWorkbook.Sheets(\"BOM\")\n \n ' Create new worksheets for output\n On Error Resume Next\n Application.DisplayAlerts = False\n ThisWorkbook.Sheets(\"Output\").Delete\n ThisWorkbook.Sheets(\"Unmatched\").Delete\n Application.DisplayAlerts = True\n On Error GoTo 0\n \n Set wsOutput = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))\n wsOutput.Name = \"Output\"\n Set wsUnmatched = ThisWorkbook.Sheets.Add(After:=wsOutput)\n wsUnmatched.Name = \"Unmatched\"\n \n ' Phase 1: Read BOM data into dictionary\n lastRowB = wsBOM.Cells(wsBOM.Rows.Count, \"A\").End(xlUp).Row\n Dim bomData As Variant\n bomData = wsBOM.Range(\"A2:C\" \u0026 lastRowB).Value\n \n For i = 1 To UBound(bomData, 1)\n keyPart = Trim(bomData(i, 1) \u0026 \"\")\n material = Trim(bomData(i, 2) \u0026 \"\")\n \n ' Safe handling of usage value\n If IsNumeric(bomData(i, 3)) Then\n usage = CDbl(bomData(i, 3))\n Else\n usage = 0\n End If\n \n If keyPart \u003c\u003e \"\" And material \u003c\u003e \"\" Then\n If Not dictBOM.Exists(keyPart) Then\n dictBOM.Add keyPart, New Collection\n End If\n dictBOM(keyPart).Add Array(material, usage)\n End If\n Next i\n \n ' Phase 2: Process Focest data - only process rows with BOM matches\n lastRowF = wsFocest.Cells(wsFocest.Rows.Count, \"A\").End(xlUp).Row\n Dim focestData As Variant\n focestData = wsFocest.Range(\"A2:BJ\" \u0026 lastRowF).Value ' Columns A to BJ (A, B + 56 weeks)\n \n ' Pre-calculate output data size\n Dim outputRowCount As Long\n outputRowCount = 0\n For i = 1 To UBound(focestData, 1)\n keyPart = Trim(focestData(i, 1) \u0026 \"\")\n If keyPart \u003c\u003e \"\" And dictBOM.Exists(keyPart) Then\n outputRowCount = outputRowCount + dictBOM(keyPart).Count\n End If\n Next i\n \n ' Prepare output array\n Dim outputData() As Variant\n ReDim outputData(1 To outputRowCount, 1 To 60) ' 4 fixed columns + 56 week columns\n \n lastRowO = 0\n \n For i = 1 To UBound(focestData, 1)\n keyPart = Trim(focestData(i, 1) \u0026 \"\")\n If keyPart = \"\" Then GoTo NextFocestRow\n \n ' Only process rows with BOM matches\n If dictBOM.Exists(keyPart) Then\n focestCol1 = focestData(i, 1) \u0026 \"\"\n focestCol2 = focestData(i, 2) \u0026 \"\"\n \n ' Safe handling of LIC value\n If IsNumeric(focestData(i, 2)) Then\n lic = CDbl(focestData(i, 2))\n Else\n lic = 0\n End If\n \n ' Extract week values with error handling\n For j = 1 To 56\n If IsNumeric(focestData(i, j + 2)) Then\n weekValues(j) = CDbl(focestData(i, j + 2))\n Else\n weekValues(j) = 0\n End If\n Next j\n \n ' Process matching BOM items\n For k = 1 To dictBOM(keyPart).Count\n materialData = dictBOM(keyPart)(k)\n material = materialData(0)\n usage = materialData(1)\n lastRowO = lastRowO + 1\n \n outputData(lastRowO, 1) = focestCol1\n outputData(lastRowO, 2) = focestCol2\n outputData(lastRowO, 3) = material\n outputData(lastRowO, 4) = usage\n \n For col = 1 To 56\n outputData(lastRowO, col + 4) = weekValues(col) * lic * usage\n Next col\n Next k\n End If\n \nNextFocestRow:\n Next i\n \n ' Phase 3: Separately process Focest rows without BOM matches\n For i = 1 To UBound(focestData, 1)\n keyPart = Trim(focestData(i, 1) \u0026 \"\")\n If keyPart \u003c\u003e \"\" And Not dictBOM.Exists(keyPart) Then\n If Not dictUnmatched.Exists(keyPart) Then\n dictUnmatched.Add keyPart, True\n End If\n End If\n Next i\n \n ' Batch write output data\n If outputRowCount \u003e 0 Then\n wsOutput.Range(\"A2\").Resize(outputRowCount, 60).Value = outputData\n End If\n \n ' Generate unmatched sheet\n wsUnmatched.Cells(1, 1).Value = \"Unmatched Key Part Numbers\"\n \n If dictUnmatched.Count \u003e 0 Then\n Dim unmatchedData() As Variant\n ReDim unmatchedData(1 To dictUnmatched.Count, 1 To 1)\n i = 0\n For Each key In dictUnmatched.Keys\n i = i + 1\n unmatchedData(i, 1) = key\n Next key\n wsUnmatched.Range(\"A2\").Resize(dictUnmatched.Count, 1).Value = unmatchedData\n End If\n \n ' Set headers\n wsOutput.Cells(1, 1).Value = \"Focest Col1\"\n wsOutput.Cells(1, 2).Value = \"Focest Col2\"\n wsOutput.Cells(1, 3).Value = \"Material Number\"\n wsOutput.Cells(1, 4).Value = \"BOM Usage\"\n For col = 1 To 56\n wsOutput.Cells(1, col + 4).Value = \"Week\" \u0026 col\n Next col\n \n ' Auto-fit columns\n wsOutput.Columns.AutoFit\n wsUnmatched.Columns.AutoFit\n \n Application.ScreenUpdating = True\n Application.Calculation = xlCalculationAutomatic\n Application.EnableEvents = True\n \n MsgBox \"Processing completed! \" \u0026 outputRowCount \u0026 \" rows generated in Output sheet. \" \u0026 _\n dictUnmatched.Count \u0026 \" unmatched items found.\"\nEnd Sub\n"},{"Type":"NodeCodeBlockFenceCloseMarker","Data":"```"}]},{"ID":"20250917132107-urw7pf9","Type":"NodeParagraph","Properties":{"id":"20250917132107-urw7pf9","updated":"20250917132107"},"Children":[{"Type":"NodeText","Data":"C副逻辑生成数据透视表聚和取数"}]},{"ID":"20250917132107-1n9mg5m","Type":"NodeCodeBlock","IsFencedCodeBlock":true,"Properties":{"id":"20250917132107-1n9mg5m","updated":"20250917154642"},"Children":[{"Type":"NodeCodeBlockFenceOpenMarker","Data":"```"},{"Type":"NodeCodeBlockFenceInfoMarker","CodeBlockInfo":"dmJh"},{"Type":"NodeCodeBlockCode","Data":"Sub Q()\n \n ' Define variables\n Dim wsSource As Worksheet, wsDest As Worksheet\n Dim pvtCache As PivotCache\n Dim pvtTable As PivotTable\n Dim LastRow As Long, LastCol As Long\n Dim SourceDataRange As Range\n Dim i As Integer\n Dim FieldName As String\n Dim wsExists As Boolean\n Dim ptExists As Boolean\n \n ' Disable screen updating and automatic calculation for performance\n Application.ScreenUpdating = False\n Application.Calculation = xlCalculationManual\n Application.DisplayAlerts = False ' Suppress confirmation messages\n \n ' Set source data worksheet\n Set wsSource = ThisWorkbook.Worksheets(\"Output\")\n \n ' Check if destination worksheet already exists and delete it\n wsExists = False\n On Error Resume Next ' Prevent error if worksheet doesn't exist\n Set wsDest = ThisWorkbook.Worksheets(\"Cutput\")\n On Error GoTo 0\n \n If Not wsDest Is Nothing Then\n Application.DisplayAlerts = False\n wsDest.Delete\n Application.DisplayAlerts = True\n Set wsDest = Nothing\n End If\n \n ' Check if pivot table already exists in any worksheet and delete it\n ptExists = False\n Dim ws As Worksheet\n Dim pt As PivotTable\n For Each ws In ThisWorkbook.Worksheets\n For Each pt In ws.PivotTables\n If pt.Name = \"WeeklySummaryPivot\" Then\n pt.TableRange2.Clear\n ptExists = True\n End If\n Next pt\n Next ws\n \n ' Create a new worksheet for the pivot table\n Set wsDest = ThisWorkbook.Worksheets.Add\n wsDest.Name = \"Cutput\" ' Name the new worksheet\n \n ' Find the last row and last column of source data to define dynamic range\n LastRow = wsSource.Cells(wsSource.Rows.Count, 1).End(xlUp).Row\n LastCol = wsSource.Cells(1, wsSource.Columns.Count).End(xlToLeft).Column\n Set SourceDataRange = wsSource.Range(wsSource.Cells(1, 1), wsSource.Cells(LastRow, LastCol))\n \n ' Create pivot cache\n Set pvtCache = ThisWorkbook.PivotCaches.Create( _\n SourceType:=xlDatabase, _\n SourceData:=SourceDataRange)\n \n ' Create pivot table in destination worksheet - start at A1 for better positioning\n Set pvtTable = pvtCache.CreatePivotTable( _\n TableDestination:=wsDest.Range(\"A1\"), _\n TableName:=\"WeeklySummaryPivot\")\n \n ' Configure pivot table fields\n With pvtTable\n ' Change layout to tabular form for more compact display\n .RowAxisLayout xlTabularRow\n \n ' Add row field (group by)\n .PivotFields(\"Material Number\").Orientation = xlRowField\n \n ' Loop to add all week fields (week1 to week56) to values area and set to sum\n For i = 2 To LastCol\n FieldName = wsSource.Cells(1, i).Value\n If InStr(1, FieldName, \"week\", vbTextCompare) \u003e 0 Then\n With .PivotFields(FieldName)\n .Orientation = xlDataField\n .Function = xlSum\n ' 移除了NumberFormat设置保持原始数字格式\n ' .NumberFormat = \"#,##0\"\n ' Remove \"Sum of\" prefix for cleaner headers\n .Caption = Replace(.Caption, \"Sum of \", \"\")\n End With\n End If\n Next i\n \n ' Additional formatting options\n .ShowTableStyleRowStripes = True\n .ShowTableStyleColumnStripes = False\n End With\n \n ' Apply a predefined style\n pvtTable.TableStyle2 = \"PivotStyleMedium9\"\n \n ' Auto-fit columns for better visibility\n wsDest.Columns(\"A:BC\").AutoFit\n \n ' 恢复原始数字格式 - 复制源数据的格式\n For i = 2 To LastCol\n FieldName = wsSource.Cells(1, i).Value\n If InStr(1, FieldName, \"week\", vbTextCompare) \u003e 0 Then\n ' 获取源数据的列格式并应用到数据透视表对应列\n Dim sourceColFormat As String\n sourceColFormat = wsSource.Cells(2, i).NumberFormat\n wsDest.Cells(2, i).NumberFormat = sourceColFormat\n End If\n Next i\n \n ' Restore settings\n Application.DisplayAlerts = True\n Application.Calculation = xlCalculationAutomatic\n Application.ScreenUpdating = True\n \n ' Completion message\n MsgBox \"Pivot table created successfully! Located in worksheet: \" \u0026 wsDest.Name, vbInformation\n \nEnd Sub\n\n"},{"Type":"NodeCodeBlockFenceCloseMarker","Data":"```"}]},{"ID":"20250917154425-k4p218g","Type":"NodeThematicBreak","Properties":{"id":"20250917154425-k4p218g","updated":"20250917154425"}},{"ID":"20250919091921-w5kzg62","Type":"NodeParagraph","Properties":{"id":"20250919091921-w5kzg62","updated":"20250919091929"},"Children":[{"Type":"NodeText","Data":"数据透视表v2.0"}]},{"ID":"20250919091930-wn9e9sh","Type":"NodeCodeBlock","IsFencedCodeBlock":true,"Properties":{"id":"20250919091930-wn9e9sh","updated":"20250919101849"},"Children":[{"Type":"NodeCodeBlockFenceOpenMarker","Data":"```"},{"Type":"NodeCodeBlockFenceInfoMarker","CodeBlockInfo":"dmJh"},{"Type":"NodeCodeBlockCode","Data":"Sub Q()\n' Define variables\nDim wsSource As Worksheet, wsDest As Worksheet\nDim pvtCache As PivotCache\nDim pvtTable As PivotTable\nDim LastRow As Long\nDim SourceDataRange As Range\nDim i As Long\nDim fieldName As String\nDim startTime As Double\nDim dataField As PivotField\n\n' Start timing execution\nstartTime = Timer\n\n' Disable Excel features for performance optimization\nOptimizeVBA True\n\nOn Error GoTo ErrorHandler\n\n' Check if source worksheet exists\nIf Not WorksheetExists(\"Output\") Then\n MsgBox \"Source worksheet 'Output' not found!\", vbCritical\n GoTo CleanUp\nEnd If\n\n' Set reference to source worksheet\nSet wsSource = ThisWorkbook.Worksheets(\"Output\")\n\n' Delete destination worksheet if it already exists\nIf WorksheetExists(\"Cutput\") Then\n Application.DisplayAlerts = False\n ThisWorkbook.Worksheets(\"Cutput\").Delete\n Application.DisplayAlerts = True\nEnd If\n\n' Remove any existing pivot table with the same name\nRemovePivotTable \"WeeklySummaryPivot\"\n\n' Create new worksheet for the pivot table\nSet wsDest = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))\nwsDest.Name = \"Cutput\"\n\n' Find the last row with data in source worksheet\nLastRow = FindLastRow(wsSource)\n\n' Verify there is sufficient data\nIf LastRow \u003c 2 Then\n MsgBox \"Insufficient data in source worksheet!\", vbExclamation\n GoTo CleanUp\nEnd If\n\n' Define source data range\nSet SourceDataRange = wsSource.Range(\"A1:BH\" \u0026 LastRow)\n\n' Create pivot cache from source data\nSet pvtCache = ThisWorkbook.PivotCaches.Create( _\n SourceType:=xlDatabase, _\n SourceData:=SourceDataRange)\n\nSet pvtTable = pvtCache.CreatePivotTable( _\n TableDestination:=wsDest.Range(\"A3\"), _\n tableName:=\"WeeklySummaryPivot\")\n\n\nWith pvtTable\n .ManualUpdate = True\n .RowAxisLayout xlTabularRow\n \n ' Add row field - Material Number (Column C)\n .AddFields RowFields:=wsSource.Cells(1, 3).Value\n \n ' Add data fields (columns E to BH)\n For i = 5 To 60\n fieldName = wsSource.Cells(1, i).Value\n \n If fieldName \u003c\u003e \"\" Then\n On Error Resume Next\n Set dataField = .PivotFields(fieldName)\n If Err.Number = 0 Then\n With dataField\n .Orientation = xlDataField\n .Function = xlSum\n .NumberFormat = \"#,##0\"\n \n If InStr(.Caption, \"Sum of\") = 0 Then\n .Caption = \"Sum of \" \u0026 fieldName\n End If\n End With\n Else\n \n Err.Clear\n End If\n On Error GoTo ErrorHandler\n End If\n Next i\n \n ' Apply formatting\n .ShowTableStyleRowStripes = True\n .TableStyle2 = \"PivotStyleMedium9\"\n .ManualUpdate = False\nEnd With\n\n' Add title and timestamp\nWith wsDest\n .Range(\"A1\").Value = \"Weekly Summary Report\"\n .Range(\"A1\").Font.Bold = True\n .Range(\"A1\").Font.Size = 14\n \n .Range(\"A2\").Value = \"Generated: \" \u0026 Now()\n .Range(\"A2\").Font.Italic = True\nEnd With\n\n' Auto-fit columns\nIf wsDest.UsedRange.Count \u003e 1 Then\n wsDest.UsedRange.Columns.AutoFit\nEnd If\n\n' Success message\nMsgBox \"Pivot table created successfully in \" \u0026 Format(Timer - startTime, \"0.00\") \u0026 _\n \" seconds! Location: Worksheet \" \u0026 wsDest.Name, vbInformation\nCleanUp:\nOptimizeVBA False\nSet pvtTable = Nothing\nSet pvtCache = Nothing\nSet SourceDataRange = Nothing\nSet wsSource = Nothing\nSet wsDest = Nothing\n\n\nExit Sub\nErrorHandler:\nMsgBox \"Error \" \u0026 Err.Number \u0026 \": \" \u0026 Err.Description \u0026 vbCrLf \u0026 _\n\"Error occurred at line: \" \u0026 Erl, vbCritical\nResume CleanUp\nEnd Sub\n\n' Helper function: Optimize VBA performance\nSub OptimizeVBA(Optimize As Boolean)\nWith Application\nIf Optimize Then\n.ScreenUpdating = False\n.Calculation = xlCalculationManual\n.DisplayAlerts = False\n.EnableEvents = False\n.StatusBar = \"Processing... Please wait\"\nElse\n.ScreenUpdating = True\n.Calculation = xlCalculationAutomatic\n.DisplayAlerts = True\n.EnableEvents = True\n.StatusBar = False\nEnd If\nEnd With\nEnd Sub\n\n' Helper function: Check if worksheet exists\nFunction WorksheetExists(sheetName As String) As Boolean\nOn Error Resume Next\nWorksheetExists = Not ThisWorkbook.Sheets(sheetName) Is Nothing\nOn Error GoTo 0\nEnd Function\n\n' Helper function: Remove pivot table by name\nSub RemovePivotTable(tableName As String)\nDim ws As Worksheet\nDim pt As PivotTable\n\nOn Error Resume Next\n\nFor Each ws In ThisWorkbook.Worksheets\n Set pt = ws.PivotTables(tableName)\n If Not pt Is Nothing Then\n pt.TableRange2.Clear\n Exit For\n End If\nNext ws\n\nOn Error GoTo 0\nEnd Sub\n\n' Helper function: Find last row with data\nFunction FindLastRow(ws As Worksheet) As Long\nOn Error Resume Next\nFindLastRow = ws.Cells(ws.Rows.Count, \"A\").End(xlUp).Row\nIf FindLastRow = 1 And ws.Cells(1, 1).Value = \"\" Then FindLastRow = 0\nIf Err.Number \u003c\u003e 0 Then FindLastRow = 0\nOn Error GoTo 0\nEnd Function\n\n"},{"Type":"NodeCodeBlockFenceCloseMarker","Data":"```"}]},{"ID":"20250917154936-noof8l4","Type":"NodeThematicBreak","Properties":{"id":"20250917154936-noof8l4","updated":"20250917154936"}},{"ID":"20250917154936-2z7uytb","Type":"NodeHeading","HeadingLevel":3,"Properties":{"id":"20250917154936-2z7uytb","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"总体流程概述 (Sub A)"}]},{"ID":"20250917154936-727syoj","Type":"NodeParagraph","Properties":{"id":"20250917154936-727syoj","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":""},{"Type":"NodeTextMark","TextMarkType":"code","TextMarkTextContent":"Sub A"},{"Type":"NodeText","Data":" 是主程序,它按顺序调用另外两个子过程,完成了从数据处理到最终汇总的全套工作流。"}]},{"ID":"20250917154936-hpg8ji2","Type":"NodeCodeBlock","IsFencedCodeBlock":true,"Properties":{"id":"20250917154936-hpg8ji2","updated":"20250917154936"},"Children":[{"Type":"NodeCodeBlockFenceOpenMarker","Data":"```"},{"Type":"NodeCodeBlockFenceInfoMarker","CodeBlockInfo":"dmJh"},{"Type":"NodeCodeBlockCode","Data":"Sub A()\n Call B ' 第一步执行B过程进行数据匹配和计算\n Call Q ' 第二步执行Q过程创建数据透视表进行汇总\nEnd Sub\n"},{"Type":"NodeCodeBlockFenceCloseMarker","Data":"```"}]},{"ID":"20250917154936-xwk3lxu","Type":"NodeThematicBreak","Properties":{"id":"20250917154936-xwk3lxu","updated":"20250917154936"}},{"ID":"20250917154936-440ppaz","Type":"NodeHeading","HeadingLevel":3,"Properties":{"id":"20250917154936-440ppaz","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"1. 过程 B 的功能:数据匹配与计算"}]},{"ID":"20250917154936-1hraucx","Type":"NodeParagraph","Properties":{"id":"20250917154936-1hraucx","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"核心目标:"},{"Type":"NodeText","Data":" 将“需求预测”和“物料清单BOM”两个数据源进行匹配关联计算出每种物料在未来56周内的详细需求计划并找出无法匹配的项。"}]},{"ID":"20250917154936-24hidzb","Type":"NodeParagraph","Properties":{"id":"20250917154936-24hidzb","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"详细步骤分解:"}]},{"ID":"20250917154936-gupl97d","Type":"NodeList","ListData":{"Typ":1},"Properties":{"id":"20250917154936-gupl97d","updated":"20250917154936"},"Children":[{"ID":"20250917154936-rdarsw3","Type":"NodeListItem","ListData":{"Typ":1,"Delimiter":46,"Marker":"MS4=","Num":1},"Properties":{"id":"20250917154936-rdarsw3","updated":"20250917154936"},"Children":[{"ID":"20250917154936-n6tfg3v","Type":"NodeParagraph","Properties":{"id":"20250917154936-n6tfg3v","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"准备工作表"}]},{"ID":"20250917154936-s1u4svb","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-s1u4svb","updated":"20250917154936"},"Children":[{"ID":"20250917154936-smu2jwx","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-smu2jwx","updated":"20250917154936"},"Children":[{"ID":"20250917154936-aties3p","Type":"NodeParagraph","Properties":{"id":"20250917154936-aties3p","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"删除并重建输出表:"},{"Type":"NodeText","Data":" 程序会先检查并删除名为“Output”和“Unmatched”的工作表如果存在然后重新创建它们。这确保了每次运行都是从零开始的干净状态。"}]}]}]}]},{"ID":"20250917154936-bzdebsy","Type":"NodeListItem","ListData":{"Typ":1,"Delimiter":46,"Marker":"Mi4=","Num":2},"Properties":{"id":"20250917154936-bzdebsy","updated":"20250917154936"},"Children":[{"ID":"20250917154936-x6odhay","Type":"NodeParagraph","Properties":{"id":"20250917154936-x6odhay","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"读取BOM数据构建字典"}]},{"ID":"20250917154936-gvmd9l7","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-gvmd9l7","updated":"20250917154936"},"Children":[{"ID":"20250917154936-eklewiw","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-eklewiw","updated":"20250917154936"},"Children":[{"ID":"20250917154936-oyp24we","Type":"NodeParagraph","Properties":{"id":"20250917154936-oyp24we","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"数据源:"},{"Type":"NodeText","Data":" “BOM”工作表。"}]}]},{"ID":"20250917154936-ymhcwy2","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-ymhcwy2","updated":"20250917154936"},"Children":[{"ID":"20250917154936-eh8hj4o","Type":"NodeParagraph","Properties":{"id":"20250917154936-eh8hj4o","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"关键技术:"},{"Type":"NodeText","Data":" 使用 "},{"Type":"NodeTextMark","TextMarkType":"strong code","TextMarkTextContent":"Scripting.Dictionary"},{"Type":"NodeText","Data":" 对象创建一个高效的查找字典。"}]}]},{"ID":"20250917154936-6q1zkkb","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-6q1zkkb","updated":"20250917154936"},"Children":[{"ID":"20250917154936-o8fxqxf","Type":"NodeParagraph","Properties":{"id":"20250917154936-o8fxqxf","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"字典结构:"}]},{"ID":"20250917154936-dy1klmx","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-dy1klmx","updated":"20250917154936"},"Children":[{"ID":"20250917154936-el8cx2n","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-el8cx2n","updated":"20250917154936"},"Children":[{"ID":"20250917154936-u8cfwk2","Type":"NodeParagraph","Properties":{"id":"20250917154936-u8cfwk2","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"键 (Key):"},{"Type":"NodeText","Data":" “关键零件号”BOM表的第4列。"}]}]},{"ID":"20250917154936-gz9lz1j","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-gz9lz1j","updated":"20250917154936"},"Children":[{"ID":"20250917154936-9zb3hx5","Type":"NodeParagraph","Properties":{"id":"20250917154936-9zb3hx5","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"值 (Item):"},{"Type":"NodeText","Data":" 一个数组包含对应的“物料号”第1列和“单机用量”第5列。"}]}]}]}]},{"ID":"20250917154936-ydbpsib","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-ydbpsib","updated":"20250917154936"},"Children":[{"ID":"20250917154936-507spxa","Type":"NodeParagraph","Properties":{"id":"20250917154936-507spxa","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"目的:"},{"Type":"NodeText","Data":" 通过这个字典,可以瞬间根据“关键零件号”找到所有相关的子物料及其用量,避免了后续循环查找,极大提高了效率。"}]}]}]}]},{"ID":"20250917154936-yuv69hk","Type":"NodeListItem","ListData":{"Typ":1,"Delimiter":46,"Marker":"My4=","Num":3},"Properties":{"id":"20250917154936-yuv69hk","updated":"20250917154936"},"Children":[{"ID":"20250917154936-yd8uhh9","Type":"NodeParagraph","Properties":{"id":"20250917154936-yd8uhh9","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"处理预测数据 (Focest工作表)"}]},{"ID":"20250917154936-cixpn8w","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-cixpn8w","updated":"20250917154936"},"Children":[{"ID":"20250917154936-z408vfz","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-z408vfz","updated":"20250917154936"},"Children":[{"ID":"20250917154936-lesx13l","Type":"NodeParagraph","Properties":{"id":"20250917154936-lesx13l","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"逐行读取:"},{"Type":"NodeText","Data":" 循环读取“Focest”工作表的每一行数据从第2行开始跳过标题。"}]}]},{"ID":"20250917154936-zocfcdk","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-zocfcdk","updated":"20250917154936"},"Children":[{"ID":"20250917154936-typm96z","Type":"NodeParagraph","Properties":{"id":"20250917154936-typm96z","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"关键匹配:"},{"Type":"NodeText","Data":" 取出每一行的“关键零件号”去步骤2创建的BOM字典中进行查找。"}]}]},{"ID":"20250917154936-57rolr0","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-57rolr0","updated":"20250917154936"},"Children":[{"ID":"20250917154936-h1cuokf","Type":"NodeParagraph","Properties":{"id":"20250917154936-h1cuokf","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"匹配成功生成Output"}]},{"ID":"20250917154936-f2wi8yy","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-f2wi8yy","updated":"20250917154936"},"Children":[{"ID":"20250917154936-u3aw7n2","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-u3aw7n2","updated":"20250917154936"},"Children":[{"ID":"20250917154936-jpzoqwa","Type":"NodeParagraph","Properties":{"id":"20250917154936-jpzoqwa","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"如果找到,则获取该关键零件对应的所有物料号和用量。"}]}]},{"ID":"20250917154936-j6jfti5","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-j6jfti5","updated":"20250917154936"},"Children":[{"ID":"20250917154936-c79gm0t","Type":"NodeParagraph","Properties":{"id":"20250917154936-c79gm0t","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"核心计算:"},{"Type":"NodeText","Data":" 对于找到的每一个物料将其“单机用量”与预测数据中的“LIC”可能是计划数量以及56周中每一周的预测值相乘得到该物料每周的详细需求。"}]}]},{"ID":"20250917154936-5yw4rlh","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-5yw4rlh","updated":"20250917154936"},"Children":[{"ID":"20250917154936-6hae4wn","Type":"NodeParagraph","Properties":{"id":"20250917154936-6hae4wn","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"将所有计算结果物料号、描述、单位、以及56周的需求量写入到“Output”工作表中。"}]}]}]}]},{"ID":"20250917154936-sgwg335","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-sgwg335","updated":"20250917154936"},"Children":[{"ID":"20250917154936-1ofqwh5","Type":"NodeParagraph","Properties":{"id":"20250917154936-1ofqwh5","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"匹配失败生成Unmatched"}]},{"ID":"20250917154936-km2obcs","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-km2obcs","updated":"20250917154936"},"Children":[{"ID":"20250917154936-nh6y73f","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-nh6y73f","updated":"20250917154936"},"Children":[{"ID":"20250917154936-2ekwxnt","Type":"NodeParagraph","Properties":{"id":"20250917154936-2ekwxnt","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"如果在BOM字典中找不到当前的关键零件号则将该零件的相关信息零件号、描述写入“Unmatched”工作表用于后续检查和维护BOM。"}]}]}]}]}]}]},{"ID":"20250917154936-epplvc3","Type":"NodeListItem","ListData":{"Typ":1,"Delimiter":46,"Marker":"NC4=","Num":4},"Properties":{"id":"20250917154936-epplvc3","updated":"20250917154936"},"Children":[{"ID":"20250917154936-e55w2fe","Type":"NodeParagraph","Properties":{"id":"20250917154936-e55w2fe","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"收尾工作"}]},{"ID":"20250917154936-sydcltc","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-sydcltc","updated":"20250917154936"},"Children":[{"ID":"20250917154936-tbtua1u","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-tbtua1u","updated":"20250917154936"},"Children":[{"ID":"20250917154936-3eqjjlj","Type":"NodeParagraph","Properties":{"id":"20250917154936-3eqjjlj","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"自动调整“Output”和“Unmatched”工作表的列宽使数据清晰易读。"}]}]},{"ID":"20250917154936-2tkshe9","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-2tkshe9","updated":"20250917154936"},"Children":[{"ID":"20250917154936-zay4z60","Type":"NodeParagraph","Properties":{"id":"20250917154936-zay4z60","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"弹出提示框,告知用户成功生成了多少行数据。"}]}]}]}]}]},{"ID":"20250917154936-vwm0tii","Type":"NodeThematicBreak","Properties":{"id":"20250917154936-vwm0tii","updated":"20250917154936"}},{"ID":"20250917154936-3xeq1uz","Type":"NodeHeading","HeadingLevel":3,"Properties":{"id":"20250917154936-3xeq1uz","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"2. 过程 Q 的功能:创建数据透视表汇总"}]},{"ID":"20250917154936-jybc6qf","Type":"NodeParagraph","Properties":{"id":"20250917154936-jybc6qf","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"核心目标:"},{"Type":"NodeText","Data":" 将“Output”工作表中分散的、按关键零件展开的周数据按物料号进行汇总生成一个简洁明了的汇总报表。"}]},{"ID":"20250917154936-77fvyh9","Type":"NodeParagraph","Properties":{"id":"20250917154936-77fvyh9","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"详细步骤分解:"}]},{"ID":"20250917154936-j6gcqw0","Type":"NodeList","ListData":{"Typ":1},"Properties":{"id":"20250917154936-j6gcqw0","updated":"20250917154936"},"Children":[{"ID":"20250917154936-x58m42l","Type":"NodeListItem","ListData":{"Typ":1,"Delimiter":46,"Marker":"MS4=","Num":1},"Properties":{"id":"20250917154936-x58m42l","updated":"20250917154936"},"Children":[{"ID":"20250917154936-3i28nf7","Type":"NodeParagraph","Properties":{"id":"20250917154936-3i28nf7","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"准备工作表"}]},{"ID":"20250917154936-t2wg9xj","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-t2wg9xj","updated":"20250917154936"},"Children":[{"ID":"20250917154936-93azrdr","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-93azrdr","updated":"20250917154936"},"Children":[{"ID":"20250917154936-06u12nt","Type":"NodeParagraph","Properties":{"id":"20250917154936-06u12nt","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"删除已存在的“Cutput”工作表如果存在并重新创建一个新的“Cutput”表。"}]}]}]}]},{"ID":"20250917154936-js3a71b","Type":"NodeListItem","ListData":{"Typ":1,"Delimiter":46,"Marker":"Mi4=","Num":2},"Properties":{"id":"20250917154936-js3a71b","updated":"20250917154936"},"Children":[{"ID":"20250917154936-vh41sie","Type":"NodeParagraph","Properties":{"id":"20250917154936-vh41sie","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"定义数据源"}]},{"ID":"20250917154936-rqliivf","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-rqliivf","updated":"20250917154936"},"Children":[{"ID":"20250917154936-scsn9ku","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-scsn9ku","updated":"20250917154936"},"Children":[{"ID":"20250917154936-emqledk","Type":"NodeParagraph","Properties":{"id":"20250917154936-emqledk","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"动态定位“Output”工作表中的数据区域确保即使数据量变化数据透视表也能获取到完整的范围。"}]}]}]}]},{"ID":"20250917154936-o93x9v5","Type":"NodeListItem","ListData":{"Typ":1,"Delimiter":46,"Marker":"My4=","Num":3},"Properties":{"id":"20250917154936-o93x9v5","updated":"20250917154936"},"Children":[{"ID":"20250917154936-ck8dhy3","Type":"NodeParagraph","Properties":{"id":"20250917154936-ck8dhy3","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"创建数据透视表"}]},{"ID":"20250917154936-cmt6x1n","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-cmt6x1n","updated":"20250917154936"},"Children":[{"ID":"20250917154936-3nu0r8d","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-3nu0r8d","updated":"20250917154936"},"Children":[{"ID":"20250917154936-xewutio","Type":"NodeParagraph","Properties":{"id":"20250917154936-xewutio","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"位置:"},{"Type":"NodeText","Data":" 新创建的“Cutput”工作表。"}]}]},{"ID":"20250917154936-ug3a64r","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-ug3a64r","updated":"20250917154936"},"Children":[{"ID":"20250917154936-fomjxc3","Type":"NodeParagraph","Properties":{"id":"20250917154936-fomjxc3","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"行标签:"},{"Type":"NodeText","Data":" “Material Number”物料号。这将作为汇总的分类依据。"}]}]},{"ID":"20250917154936-7eg1p9r","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-7eg1p9r","updated":"20250917154936"},"Children":[{"ID":"20250917154936-vvvmo6z","Type":"NodeParagraph","Properties":{"id":"20250917154936-vvvmo6z","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"值区域:"},{"Type":"NodeText","Data":" 对“Week 1”到“Week 56”这56个字段执行 "},{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"“求和”"},{"Type":"NodeText","Data":" 操作。"}]}]},{"ID":"20250917154936-386r4io","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-386r4io","updated":"20250917154936"},"Children":[{"ID":"20250917154936-khj5az8","Type":"NodeParagraph","Properties":{"id":"20250917154936-khj5az8","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"目的:"},{"Type":"NodeText","Data":" 将同一个物料在所有关键零件、所有周次的需求量加总起来最终得到每个物料号对应的、未来56周的总需求。"}]}]}]}]},{"ID":"20250917154936-1tvd7v6","Type":"NodeListItem","ListData":{"Typ":1,"Delimiter":46,"Marker":"NC4=","Num":4},"Properties":{"id":"20250917154936-1tvd7v6","updated":"20250917154936"},"Children":[{"ID":"20250917154936-5r2b7q5","Type":"NodeParagraph","Properties":{"id":"20250917154936-5r2b7q5","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"格式化"}]},{"ID":"20250917154936-q3snkkr","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-q3snkkr","updated":"20250917154936"},"Children":[{"ID":"20250917154936-iuxeelp","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-iuxeelp","updated":"20250917154936"},"Children":[{"ID":"20250917154936-az0yglm","Type":"NodeParagraph","Properties":{"id":"20250917154936-az0yglm","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"自动调整数据透视表的列宽。"}]}]},{"ID":"20250917154936-yzxbb21","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-yzxbb21","updated":"20250917154936"},"Children":[{"ID":"20250917154936-vuzot2i","Type":"NodeParagraph","Properties":{"id":"20250917154936-vuzot2i","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"保留数值格式(如千位分隔符),使报表更专业美观。"}]}]},{"ID":"20250917154936-wbsufax","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-wbsufax","updated":"20250917154936"},"Children":[{"ID":"20250917154936-vu0jizy","Type":"NodeParagraph","Properties":{"id":"20250917154936-vu0jizy","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"恢复Excel的屏幕更新和计算模式提升性能体验。"}]}]}]}]},{"ID":"20250917154936-5yr9hjt","Type":"NodeListItem","ListData":{"Typ":1,"Delimiter":46,"Marker":"NS4=","Num":5},"Properties":{"id":"20250917154936-5yr9hjt","updated":"20250917154936"},"Children":[{"ID":"20250917154936-qwbv5pw","Type":"NodeParagraph","Properties":{"id":"20250917154936-qwbv5pw","updated":"20250917154936"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"完成提示"}]},{"ID":"20250917154936-yxedu6s","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-yxedu6s","updated":"20250917154936"},"Children":[{"ID":"20250917154936-j2tcjld","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-j2tcjld","updated":"20250917154936"},"Children":[{"ID":"20250917154936-dpnoegc","Type":"NodeParagraph","Properties":{"id":"20250917154936-dpnoegc","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"弹出提示框告知用户数据透视表已创建成功。"}]}]}]}]}]},{"ID":"20250917154936-dui4f70","Type":"NodeThematicBreak","Properties":{"id":"20250917154936-dui4f70","updated":"20250917154936"}},{"ID":"20250917154936-uglifo2","Type":"NodeHeading","HeadingLevel":3,"Properties":{"id":"20250917154936-uglifo2","updated":"20250918091213"},"Children":[{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"总结"}]},{"ID":"20250917154936-yvx2sw0","Type":"NodeParagraph","Properties":{"id":"20250917154936-yvx2sw0","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":"这三个过程组成了一个"},{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"完整、自动化"},{"Type":"NodeText","Data":"的ERP辅助数据处理流水线"}]},{"ID":"20250917154936-63ao4oy","Type":"NodeList","ListData":{},"Properties":{"id":"20250917154936-63ao4oy","updated":"20250917154936"},"Children":[{"ID":"20250917154936-p9inopg","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-p9inopg","updated":"20250917154936"},"Children":[{"ID":"20250917154936-bh9e7r5","Type":"NodeParagraph","Properties":{"id":"20250917154936-bh9e7r5","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":""},{"Type":"NodeTextMark","TextMarkType":"strong code","TextMarkTextContent":"Sub B"},{"Type":"NodeText","Data":""},{"Type":"NodeText","Data":" "},{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"(工程师):"},{"Type":"NodeText","Data":" 负责最复杂的"},{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"数据清洗、关联和计算"},{"Type":"NodeText","Data":"。它像是一个生产线,将原始零件和预测数据加工成详细的物料需求计划。"}]}]},{"ID":"20250917154936-6d27cgs","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-6d27cgs","updated":"20250917154936"},"Children":[{"ID":"20250917154936-x0bow1u","Type":"NodeParagraph","Properties":{"id":"20250917154936-x0bow1u","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":""},{"Type":"NodeTextMark","TextMarkType":"strong code","TextMarkTextContent":"Sub Q"},{"Type":"NodeText","Data":""},{"Type":"NodeText","Data":" "},{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"(分析师):"},{"Type":"NodeText","Data":" 负责"},{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"总结和报告"},{"Type":"NodeText","Data":"。它将生产线出来的详细产品打包成一份高层管理更容易理解的汇总报告。"}]}]},{"ID":"20250917154936-3wi5k2v","Type":"NodeListItem","ListData":{"BulletChar":42,"Marker":"Kg=="},"Properties":{"id":"20250917154936-3wi5k2v","updated":"20250917154936"},"Children":[{"ID":"20250917154936-zbemzk5","Type":"NodeParagraph","Properties":{"id":"20250917154936-zbemzk5","updated":"20250917154936"},"Children":[{"Type":"NodeText","Data":""},{"Type":"NodeTextMark","TextMarkType":"strong code","TextMarkTextContent":"Sub A"},{"Type":"NodeText","Data":""},{"Type":"NodeText","Data":" "},{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"(项目经理):"},{"Type":"NodeText","Data":" 负责"},{"Type":"NodeTextMark","TextMarkType":"strong","TextMarkTextContent":"协调整个项目"},{"Type":"NodeText","Data":",只需一个指令,就能让“工程师”和“分析师”接连工作,交付最终成果。"}]}]}]},{"ID":"20250917154936-a10pgz6","Type":"NodeParagraph","Properties":{"id":"20250917154936-a10pgz6","updated":"20250918091127"},"Children":[{"Type":"NodeText","Data":"这种结构非常高效且易于维护,用户只需运行一次 "},{"Type":"NodeTextMark","TextMarkType":"code","TextMarkTextContent":"Sub A"},{"Type":"NodeText","Data":"​,即可获得从明细到汇总的所有结果。"}]},{"ID":"20250918091112-9j81670","Type":"NodeHeading","HeadingLevel":4,"Properties":{"id":"20250918091112-9j81670","updated":"20250918091213"},"Children":[{"Type":"NodeText","Data":"额外函数,正则匹配"}]},{"ID":"20250918091113-enryugw","Type":"NodeCodeBlock","IsFencedCodeBlock":true,"Properties":{"id":"20250918091113-enryugw","updated":"20250918091121"},"Children":[{"Type":"NodeCodeBlockFenceOpenMarker","Data":"```"},{"Type":"NodeCodeBlockFenceInfoMarker","CodeBlockInfo":"dmJh"},{"Type":"NodeCodeBlockCode","Data":"Function ra(inputText As String) As String\n Dim regex As Object\n Dim matches As Object\n Set regex = CreateObject(\"VBScript.RegExp\")\n \n With regex\n .Pattern = \"[A-Z0-9-]{6,25}\"\n .Global = True\n End With\n \n Set matches = regex.Execute(inputText)\n \n If matches.Count \u003e 0 Then\n ra = matches(0).Value\n Else\n ra = \"NO\"\n End If\nEnd Function\n"},{"Type":"NodeCodeBlockFenceCloseMarker","Data":"```"}]}]}