1 line
51 KiB
Plaintext
1 line
51 KiB
Plaintext
|
|
{"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 \
|