返回列表 上一主題 發帖

請問規則02F - 04F 如果在Data Base 篩選在這個範圍内的相關資料

回復  198188


    恭喜前輩
Form 的部分已經處理好了,但外出中 星期一才能提供測試
請前輩將Data  ...
Andy2483 發表於 2025-10-31 12:45



    好的,謝謝前輩

TOP

回復  198188


    恭喜前輩
Form 的部分已經處理好了,但外出中 星期一才能提供測試
請前輩將Data  ...
Andy2483 發表於 2025-10-31 12:45



前輩可否上載Form 給我測試

TOP

回復  198188


    前輩沒先傳DATA OK版本給後學確認,那就再請前輩確認以下方案是否符合需求

Sub D ...
Andy2483 發表於 2025-11-3 10:33


前輩,我上傳了, 在#124

TOP

回復  198188


    前輩沒先傳DATA OK版本給後學確認,那就再請前輩確認以下方案是否符合需求

Sub D ...
Andy2483 發表於 2025-11-3 10:33



   
  1. Sub Data()
  2. Dim Arr, Brr, Crr, Z, Q, S, i&, j%, N&, T$, T1$, MyPath$, xFile$, xBook As Workbook, Re, R&
  3. Dim rng, cell As Range

  4. Application.ScreenUpdating = False
  5. For Each S In [{"Layout Dwg","Frame per Dwg","Part List"}]
  6.    Sheets(S).UsedRange.Rows.Offset(1).EntireRow.Delete
  7.    'Delete Old data of "Layout Dwg","Frame per Dwg","Part List" from this workbook
  8. Next
  9. MyPath = ThisWorkbook.Path & "\"
  10. xFile = "Data Base.xlsx"
  11. On Error Resume Next
  12. Set xBook = Workbooks(xFile)
  13. If xBook Is Nothing Then
  14.    Set xBook = Workbooks.Open(MyPath & xFile, , True, , "")
  15.    Re = True: ThisWorkbook.Activate
  16. End If
  17. On Error GoTo 0
  18. Set Z = CreateObject("Scripting.Dictionary")
  19. T = Sheets("Read").[A2] & "|" & Sheets("Read").[C2]
  20. T1 = Sheets("Read").[B2]
  21. With xBook.Sheets("WO No")
  22.    For i = 2 To .[A65536].End(3).Row
  23.       If .Cells(i, "B") & "|" & .Cells(i, "D") = T Then
  24.          .Rows(i).Copy Sheets("WO No").Rows(2)
  25.          For j = 6 To 11
  26.             Z("|" & .Cells(i, j)) = ""
  27.             'Let Column F-K of WO No Sheet as KEY item and add "|" between each word then put into dictionary
  28.          Next
  29.          Sheets("Read").[A2].Resize(, 3).Copy Sheets("WO No").[B2]
  30.          GoTo 11
  31.       End If
  32.    Next
  33.    MsgBox "Nothing": Exit Sub
  34. End With
  35. 11
  36. If T1 Like "##F-*##F" Then
  37.    For i = Val(T1) To Val(StrReverse(Mid(StrReverse(T1), 2, 2)))
  38.       Z(Format(i, "00F")) = ""
  39.    Next
  40.    Else
  41.       Q = Split(T1 & "&" & T1, "&")
  42.       For i = 0 To UBound(Q)
  43.          Z(Q(i)) = 0
  44.       Next
  45. End If
  46. Brr = xBook.Sheets("Layout Dwg").UsedRange
  47. For i = 2 To UBound(Brr)
  48.    If Z.Exists(Brr(i, 2)) And Brr(i, 4) = Sheets("Read").[A2] Then
  49.       'If match of column B floor and column D batch
  50.       Z(Brr(i, 1)) = Z(Brr(i, 1)) + Val(Brr(i, 3))
  51.       'Sum of column C QTY of same of column A "Distribution Map No." of "Layout Dwg" (Name as:LDTotalQTY)
  52.       N = N + 1
  53.       For j = 1 To 4: Brr(N, j) = Brr(i, j): Next
  54.    End If
  55. Next
  56. If N > 0 Then Sheets("Layout Dwg").[A2].Resize(N, 4) = Brr: N = 0 Else MsgBox "Nothing under the floor": GoTo 12
  57. Brr = xBook.Sheets("Frame per Dwg").UsedRange
  58. For i = 2 To UBound(Brr)
  59.    If Z(Brr(i, 1)) > 0 Then
  60.       N = N + 1
  61.       For j = 1 To 6: Brr(N, j) = Brr(i, j): Next
  62.       Brr(N, 5) = Brr(N, 5) * Z(Brr(i, 1))
  63.       'Let Column E QTY of "Frame per Dwg" * LDTotalQTY
  64.       If Z(Brr(i, 2)) > 0 Then
  65.          MsgBox "*Layout Dwg* A column and *Frame per Dwg* B column are duplicate" & vbLf & vbLf & Brr(i, 2)
  66.          Exit Sub
  67.       End If
  68.       Z(Brr(i, 2) & "/") = Z(Brr(i, 2) & "/") + Brr(N, 5)
  69.       'Sum of Column E QTY of "Frame per Dwg" Column B "Assembly Drawing No." (Name as: FDTotalQTY)
  70.    End If
  71. Next
  72. If N > 0 Then Sheets("Frame per Dwg").[A2].Resize(N, 6) = Brr: N = 0 Else MsgBox "Frame per Dwg_Nothing"

  73. Brr = xBook.Sheets("Part List").UsedRange
  74. ReDim Arr(1 To 100000, 1 To 13): Crr = Arr
  75. For i = 2 To UBound(Brr)
  76.    T = Brr(i, 8)
  77.    If T Like "*[a-z]" Then Q = Left(T, Len(T) - 1) Else Q = "||"
  78.    If Z(T) > 0 Or Z(Q) > 0 Then
  79.    Set rng = Sheets("Frame per Dwg").Columns("A:A")
  80.    Set cell = rng.Find(What:=T, LookIn:=xlFormulas, _
  81.                     LookAt:=xlWhole, MatchCase:=False)
  82.    If cell Is Nothing Then
  83.       N = N + 1
  84.       For j = 1 To 13: Arr(N, j) = Brr(i, j): Next
  85.       Arr(N, 3) = Arr(N, 3) * (Z(T) + Z(Q))
  86.    End If
  87.    End If
  88.    '1.Filter Layout Dwg column A "Distribution Map No." of this workbook which don't appear on the Frame per Dwg of this workbook
  89.    '1.1 Match of Layout Dwg column A "Distribution Map No." of this workbook and Part List column H "Distribution Map No." of Data Base workbook
  90.    '1.2 If (1.) Match, list out the row on Part List of this workbook and column C QTY * LDTotalQTY
  91.    '1.3 If the last word column H is lowercase letter of "Part List" of Data Base workbook, then remove the lowercase letter and match column A of "Layout Dwg" of this workbook, then list out the row on Part List of this workbook and column C QTY * LDTotalQTY
  92.    If Z(T & "/") > 0 And Z.Exists("|" & Left(T, 2)) Then
  93.       R = R + 1
  94.       For j = 1 To 13: Crr(R, j) = Brr(i, j): Next
  95.       Crr(R, 3) = Crr(R, 3) * Z(T & "/")
  96.       '2. Column B "Assembly Drawing No." of "Frame per Dwg" of this workbook including column F-K of WO No, then match column H "Distribution Map No." of "Part List" of Data Base workbook
  97.       '2.1 If (2.1) match, list out the row on Part List of this workbook and column C QTY * FDTotalQTY
  98.    End If
  99. Next
  100. If N > 0 Then
  101.    With Sheets("Part List").[A2].Resize(N, 13)
  102.       .Value = Arr
  103.       .Interior.ColorIndex = 35
  104.       'Let Green which item list out by "Distribution Map No."
  105.    End With
  106. End If
  107. If R > 0 Then
  108.    With Sheets("Part List").Cells(N + 2, 1).Resize(R, 13)
  109.       .Value = Crr
  110.       .Interior.ColorIndex = 36
  111.       'Let Yellow which item list out by "Assembly Drawing No."
  112.    End With
  113. End If
  114. If N + R = 0 Then MsgBox "Part List_Nothing"
  115. 12: If Re = True Then xBook.Close 0
  116. End Sub
複製代碼
你這個還是資料不全,舉例圖片,BC 這些應該出現在 本檔的part list,但是沒有。

我的這個就沒問題,出現資料齊全。

TOP

回復  198188


    後學複製了124樓代碼執行的結果與後學先前版本結果相同,所以DATA部分還是沒確認好
...
Andy2483 發表於 2025-11-3 10:56



  附件是本檔每個Sheet 需要出現的資料範例。

1.rar (11.81 KB)

TOP

回復  198188


    請前輩上傳本檔檔案
Andy2483 發表於 2025-11-3 11:14



    前輩,附件是本黨檔案,
Data 是我更正後,資料正確的
DataTest 是前輩早上提供的,資料還有遺漏。

Result Test 31-Oct 2025 .rar (731.3 KB)

TOP

回復  198188


    後學複製了124樓代碼執行的結果與後學先前版本結果相同,所以DATA部分還是沒確認好
...
Andy2483 發表於 2025-11-3 10:56



前輩先前版本沒有完全過濾掉,在Frame per Dwg 出現過的 分佈圖號。
只有小寫英文字母
舉例 :BC136
導出的分佈圖,BC136, BC136a, BC136b .........BC136z 這些都會導出。

TOP

本帖最後由 198188 於 2025-11-3 14:49 編輯
回復  198188


    謝謝前輩解說,以下是FORM 代碼

Option Explicit
Dim A, Z, R&, W, L, i&, Brr, ...
Andy2483 發表於 2025-11-3 14:29




執行後,在建立新模板時,出錯。無法繼續下次

附上執行本檔範例。

Result Test 3 Nov 2025 .rar (375.94 KB)

TOP

回復  198188


    範例檔執行沒問題! 用以下條件執行DATA後 在執行 FORM 也沒問題

批次次序        樓層         ...
Andy2483 發表於 2025-11-3 14:56


前輩,是卡在copy sheet 的問題上。是否中文版亂碼導致copy問題?
   ThisWorkbook.Sheets(Z(T & "/s")).Copy Before:=Workbooks(xW).Sheets(1)

TOP

回復  198188


    Z(T & "/s") 是英文
xW 是新增 活頁簿名稱(依照所使用語言新增的名字)
Andy2483 發表於 2025-11-3 15:21



  你意思是說,xW 如果電腦是中文版,就會生產中文版嗎?不是英文版?那樣會不會有亂碼,導致生產不了?
因爲我每次運行都是在這�堨X錯。

TOP

        靜思自在 : 能幹不幹,不如苦幹實幹。
返回列表 上一主題