返回列表 上一主題 發帖

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

  1. Sub Data()
  2. Dim Arr, Brr, Crr, Z, Q, S, i&, j%, N&, T$, T1$, MyPath$, xFile$, xBook As Workbook, Re, R&
  3. Application.ScreenUpdating = False
  4. For Each S In [{"Layout Dwg","Frame per Dwg","Part List"}]
  5.    Sheets(S).UsedRange.Rows.Offset(1).EntireRow.Delete
  6. Next
  7. MyPath = ThisWorkbook.Path & "\"
  8. xFile = "Data Base1.xlsx"
  9. On Error Resume Next
  10. Set xBook = Workbooks(xFile)
  11. If xBook Is Nothing Then
  12.    Set xBook = Workbooks.Open(MyPath & xFile, , True, , "")
  13.    Re = True: ThisWorkbook.Activate
  14. End If
  15. On Error GoTo 0
  16. Set Z = CreateObject("Scripting.Dictionary")
  17. T = Sheets("Read").[A2] & "|" & Sheets("Read").[C2]
  18. T1 = Sheets("Read").[B2]
  19. With xBook.Sheets("WO No")
  20.    For i = 2 To .[A65536].End(3).Row
  21.       If .Cells(i, "B") & "|" & .Cells(i, "D") = T Then
  22.          .Rows(i).Copy Sheets("WO No").Rows(2)
  23.          For j = 6 To 11
  24.             Z("|" & .Cells(i, j)) = ""
  25.          Next
  26.          Sheets("Read").[A2].Resize(, 3).Copy Sheets("WO No").[B2]
  27.          GoTo 11
  28.       End If
  29.    Next
  30.    MsgBox "Nothing": Exit Sub
  31. End With
  32. 11
  33. If T1 Like "##F-*##F" Then
  34.    For i = Val(T1) To Val(StrReverse(Mid(StrReverse(T1), 2, 2)))
  35.       Z(Format(i, "00F")) = ""
  36.    Next
  37.    Else
  38.       Q = Split(T1 & "&" & T1, "&")
  39.       For i = 0 To UBound(Q)
  40.          Z(Q(i)) = 0
  41.       Next
  42. End If
  43. Brr = xBook.Sheets("Layout Dwg").UsedRange
  44. For i = 2 To UBound(Brr)
  45.    If Z.Exists(Brr(i, 2)) And Brr(i, 4) = Sheets("Read").[A2] Then
  46.       Z(Brr(i, 1)) = Z(Brr(i, 1)) + Val(Brr(i, 3))
  47.       N = N + 1
  48.       For j = 1 To 4: Brr(N, j) = Brr(i, j): Next
  49.    End If
  50. Next
  51. If N > 0 Then Sheets("Layout Dwg").[A2].Resize(N, 4) = Brr: N = 0 Else MsgBox "Nothing under the floor": GoTo 12
  52. Set Brr = xBook.Sheets("Frame per Dwg").UsedRange
  53. Brr = Range(Brr, Brr.Offset(, 1))
  54. For i = 2 To UBound(Brr)
  55.    If Z(Brr(i, 1)) > 0 Then
  56.       N = N + 1
  57.       For j = 1 To 6: Brr(N, j) = Brr(i, j): Next
  58.       Brr(N, 7) = Brr(N, 5) & " x " & Z(Brr(i, 1))
  59.       Brr(N, 5) = Brr(N, 5) * Z(Brr(i, 1))
  60.       Z(Brr(i, 2) & "/") = Z(Brr(i, 2) & "/") + Brr(N, 5)
  61.    End If
  62. Next
  63. For i = 1 To N
  64.    Brr(i, 1) = i
  65. Next
  66. Sheets("Frame per Dwg").[A1] = " No "
  67. If N > 0 Then Sheets("Frame per Dwg").[A2].Resize(N, 7) = Brr: N = 0 Else MsgBox "Frame per Dwg_Nothing"
  68. Brr = xBook.Sheets("Part List").UsedRange
  69. ReDim Arr(1 To 100000, 1 To 14): Crr = Arr
  70. For i = 2 To UBound(Brr)
  71.    T = Brr(i, 8): T1 = Brr(i, 7)
  72.     If (Z(T) > 0 Or Z(Q) > 0) And InStr("YO", T1) > 0 Then
  73.       N = N + 1
  74.       For j = 1 To 13: Arr(N, j) = Brr(i, j): Next
  75.       Arr(N, 14) = Arr(N, 3) & " x " & (Z(T) + Z(Q))
  76.       Arr(N, 3) = Arr(N, 3) * (Z(T) + Z(Q))
  77.    End If
  78.    If Z(T & "/") > 0 And Z.Exists("|" & Left(T, 2)) And InStr("YO", T1) = 0 Then
  79.       R = R + 1
  80.       For j = 1 To 13: Crr(R, j) = Brr(i, j): Next
  81.       Crr(R, 14) = Crr(R, 3) & " x " & Z(T & "/")
  82.       Crr(R, 3) = Crr(R, 3) * Z(T & "/")
  83.    End If
  84. Next
  85. If N > 0 Then
  86.    With Sheets("Part List").[A2].Resize(N, 14)
  87.       .Value = Arr
  88.       .Interior.ColorIndex = 35
  89.    End With
  90. End If
  91. If R > 0 Then
  92.    With Sheets("Part List").Cells(N + 2, 1).Resize(R, 14)
  93.       .Value = Crr
  94.       .Interior.ColorIndex = 36
  95.    End With
  96. End If
  97. If N + R = 0 Then MsgBox "Part List_Nothing"
  98. 12: If Re = True Then xBook.Close 0
  99. End Sub
複製代碼
回復  198188


   
1.這程式碼已經亂掉了,全部都刪除
2.複製99 樓的程式碼貼進去
3.用116樓的程式 ...
Andy2483 發表於 2025-10-30 22:26




前輩,換了之後,執行出現這個問題。

TOP

回復  198188


    會不會是系統語言不同造成的差異,請試試以下 代碼

Sub Data()
Dim Arr, Brr, C ...
Andy2483 發表於 2025-10-30 10:53


前輩,可否直接在這個程式加一個條件,篩查 將沒有在本檔Frame per Dwg 出現 的 Layout Dwg 分佈圖號,跟 Data Base Part List 分佈圖號 對比。
其他方面這個程式沒有問題了。

TOP

本帖最後由 Andy2483 於 2025-10-31 09:12 編輯
前輩,換了之後,執行出現這個問題。
198188 發表於 2025-10-31 07:43



    現在在戶外沒辦法幫測試
偵錯停下的是檢查  List檔G欄是Y或O的歸到工地用:
請查看i 執行到第幾列 並查看該列的G欄儲存格是什麼字


還有這  "Data Base1.xlsx"是正確的嗎?
還是要改成 "Data Base.xlsx"
用行動裝置瀏覽論壇學習很方便,謝謝論壇經營團隊
請大家一起上論壇來交流

TOP

現在在戶外沒辦法幫測試
偵錯停下的是檢查  List檔G欄是Y或O的歸到工地用:
請查看i 執行到第幾 ...
Andy2483 發表於 2025-10-31 09:09
  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
複製代碼
前輩,我增加了一個 set find 功能在這�堙A過濾掉出現在Frame per Dwg 的分佈圖號。
Brr = xBook.Sheets("Part List").UsedRange
ReDim Arr(1 To 100000, 1 To 13): Crr = Arr
For i = 2 To UBound(Brr)
   T = Brr(i, 8)
   If T Like "*[a-z]" Then Q = Left(T, Len(T) - 1) Else Q = "||"
   If Z(T) > 0 Or Z(Q) > 0 Then
   Set rng = Sheets("Frame per Dwg").Columns("A:A")
   Set cell = rng.Find(What:=T, LookIn:=xlFormulas, _
                    LookAt:=xlWhole, MatchCase:=False)
   If cell Is Nothing Then
      N = N + 1
      For j = 1 To 13: Arr(N, j) = Brr(i, j): Next
      Arr(N, 3) = Arr(N, 3) * (Z(T) + Z(Q))
   End If
   End If

TOP

回復  198188


    以下方案請試試看:

Option Explicit
Dim A, Z, R&, W, L, i&, Brr, Mrr, Q, Dr ...
Andy2483 發表於 2025-10-27 15:31



前輩,采用這個方案,在執行制表時,出現上圖的錯誤,無法複製表格,附上範本,請幫看看

TOP

回復 124# 198188


    所以Data部份前輩已經搞定了嗎?
用行動裝置瀏覽論壇學習很方便,謝謝論壇經營團隊
請大家一起上論壇來交流

TOP

回復  198188


    所以Data部份前輩已經搞定了嗎?
Andy2483 發表於 2025-10-31 11:32



    前輩,是的。現在Form 部分卡住了,請看 #125

TOP

回復 127# 198188


    恭喜前輩
Form 的部分已經處理好了,但外出中 星期一才能提供測試
請前輩將Data 的部分多測試各種情境,如果都ok,請上傳一份範例給後學測試
後學測試完兩個都可以執行 再提供Form
用行動裝置瀏覽論壇學習很方便,謝謝論壇經營團隊
請大家一起上論壇來交流

TOP

回復  198188


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



    好的,謝謝前輩

TOP

回復  198188


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



前輩可否上載Form 給我測試

TOP

        靜思自在 : 手心向下是助人,手心向上是求人;助人快樂,求人痛苦。
返回列表 上一主題