請問規則02F - 04F 如果在Data Base 篩選在這個範圍内的相關資料
- 帖子
- 582
- 主題
- 75
- 精華
- 0
- 積分
- 682
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-10-30
- 最後登錄
- 2026-4-13
|
請問規則02F - 04F 如果在Data Base 篩選在這個範圍内的相關資料
[attach]38095[/attach][attach]38096[/attach][attach]38097[/attach]
請問如果規則是02F - 04F 或者多個樓層,如果在Data Base 篩選在這個範圍内的相關資料。
如圖一,圖二,圖三
附上Excel Data Base & 想要的結果及規則。 |
|
|
|
|
|
|
|
- 帖子
- 582
- 主題
- 75
- 精華
- 0
- 積分
- 682
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-10-30
- 最後登錄
- 2026-4-13
|
2#
發表於 2025-10-5 16:20
| 只看該作者
|
|
|
|
|
|
|
- 帖子
- 1796
- 主題
- 184
- 精華
- 0
- 積分
- 1985
- 點名
- 0
- 作業系統
- WIN
- 軟體版本
- 2007
- 閱讀權限
- 100
- 性別
- 男
- 註冊時間
- 2015-9-11
- 最後登錄
- 2026-9-24

|
3#
發表於 2025-10-6 11:19
| 只看該作者
|
B2=VLOOKUP($A2,'[Data Base.xlsx]WO No'!$A:$K,COLUMN(B1),) |
|
|
google"EXCEL迷" blog 或google網址:https://hcm19522.blogspot.com/
|
|
|
|
|
- 帖子
- 582
- 主題
- 75
- 精華
- 0
- 積分
- 682
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-10-30
- 最後登錄
- 2026-4-13
|
4#
發表於 2025-10-6 11:36
| 只看該作者
本帖最後由 198188 於 2025-10-6 11:38 編輯
B2=VLOOKUP($A2,'[Data Base.xlsx]WO No'!$AK,COLUMN(B1),)
hcm19522 發表於 2025-10-6 11:19 
這個并非我的問題要求。
我意思是說,
我輸入02F-04F (圖1)
就會自動抽取 Layout Dwg 表�媊� B 樓層屬於這個 02F - 04F 範圍内的資料出來 (圖3)
我輸入03F-08F(圖1)
就會自動抽取 Layout Dwg 表�媊� B 樓層屬於這個 03F - 08F 範圍内的資料出來(圖3) |
|
|
|
|
|
|
|
- 帖子
- 582
- 主題
- 75
- 精華
- 0
- 積分
- 682
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-10-30
- 最後登錄
- 2026-4-13
|
5#
發表於 2025-10-8 09:11
| 只看該作者
本帖最後由 198188 於 2025-10-8 09:16 編輯
- Sub Copy_Layout_To_Data() 'ok!
- Dim h, i, j As Integer
- Dim myString, myString1 As String
- Dim charToFind, charToFind1, charToFind2 As String
- Dim position, position1, position2, position3 As Long
- Dim stringLength, stringLength1 As Long
- j = 2
-
- h = Worksheets("Layout Dwg").Cells(Rows.Count, 1).End(3).Row
- h = h + 1
-
- myString = Sheets("Data").Range("C2")
- stringLength = Len(myString)
- charToFind = "-" ' Searching for lowercase '-' in "World"
- position = InStr(1, myString, charToFind, vbTextCompare)
- If position > 0 Then
-
- a = Mid(myString, 1, position - 2)
- b = Mid(myString, position + 1, stringLength - position - 1)
-
- For i = 2 To h
- Sheets("Layout Dwg").Select
- myString1 = Range("B" & i)
- charToFind2 = "F" ' Searching for lowercase 'F' in "World"
- position2 = InStr(1, myString1, charToFind2, vbTextCompare)
-
- If position2 > 0 Then
- c = Mid(myString1, 1, position2 - 1)
- If c = a Then
- Sheets("Layout Dwg").Select
- Range("A" & i & ":C" & i).Select
- Selection.Copy
- Sheets("Data").Select
- Range("M" & j).Select
- ActiveSheet.Paste
- j = j + 1
- Else
- If c > a And c <= b Then
- Sheets("Layout Dwg").Select
- Range("A" & i & ":C" & i).Select
- Selection.Copy
- Sheets("Data").Select
- Range("M" & j).Select
- ActiveSheet.Paste
- j = j + 1
- End If
- End If
- End If
- Next i
-
- Else
- charToFind1 = "&" ' Searching for lowercase '&' in "World"
- position1 = InStr(1, myString, charToFind1, vbTextCompare)
- If position1 > 0 Then
- Z = Mid(myString, 1, position1 - 1)
- y = Mid(myString, position1 + 1, stringLength - position1)
-
- For i = 2 To h
-
- Sheets("Layout Dwg").Select
- c = Range("B" & i)
- If c = Z Or c = y Then
- Sheets("Layout Dwg").Select
- Range("A" & i & ":C" & i).Select
- Selection.Copy
- Sheets("Data").Select
- Range("M" & j).Select
- ActiveSheet.Paste
- j = j + 1
- End If
-
- Next i
-
- Else
- W = myString
- For i = 2 To h
-
- Sheets("Layout Dwg").Select
- c = Range("B" & i)
- If c = W Then
- Sheets("Layout Dwg").Select
- Range("A" & i & ":C" & i).Select
- Selection.Copy
- Sheets("Data").Select
- Range("M" & j).Select
- ActiveSheet.Paste
- j = j + 1
- End If
- Next i
-
- End If
- End If
- End Sub
複製代碼這個并非我的問題要求。
我意思是說,
我輸入02F-04F (圖1)
就會自動抽取 Layout Dwg 表�媊� B 樓層 ...
198188 發表於 2025-10-6 11:36 
嘗試用這個方式可以區別,但是運行速度太慢,請教各大大有沒有改進空間? |
|
|
|
|
|
|
|
- 帖子
- 1567
- 主題
- 40
- 精華
- 0
- 積分
- 1591
- 點名
- 0
- 作業系統
- Windows 7
- 軟體版本
- Excel 2010 & 2016
- 閱讀權限
- 100
- 性別
- 男
- 來自
- 台灣
- 註冊時間
- 2020-7-15
- 最後登錄
- 2026-2-2
|
6#
發表於 2025-10-8 14:54
| 只看該作者
本帖最後由 Andy2483 於 2025-10-8 15:28 編輯
回復 2# 198188
謝謝前輩發表此主題與範例
後學藉此帖練習陣列與字典,學習方案如下,請前輩參考
Option Explicit
Sub TEST()
Dim Brr, Z, Q, i&, j%, N&, T$, T1$, MyPath$, xFile$, xBook As Workbook, MyBook As Workbook, Re
Set Z = CreateObject("Scripting.Dictionary")
Set MyBook = ThisWorkbook
MyPath = MyBook.Path & "\"
xFile = "Data Base.xlsx"
On Error Resume Next
Set xBook = Workbooks(xFile)
If xBook Is Nothing Then
Set xBook = Workbooks.Open(MyPath & xFile, , True, , "")
Re = True
MyBook.Activate
End If
On Error GoTo 0
T = Sheets("Read").[A2] & "|" & Sheets("Read").[C2]
T1 = Sheets("Read").[B2]
With xBook.Sheets("WO No")
For i = 2 To .[A65536].End(3).Row
If .Cells(i, "B") & "|" & .Cells(i, "D") = T Then
.Rows(i).Copy Sheets("WO No").Rows(2)
Sheets("Read").[A2].Resize(, 3).Copy Sheets("WO No").[B2]
GoTo 11
End If
Next
MsgBox "Nothing": Exit Sub
End With
11
If T1 Like "##F-*##F" Then
For i = Val(T1) To Val(StrReverse(Mid(StrReverse(T1), 2, 2)))
Z(Format(i, "00F")) = ""
Next
Else
Q = Split(T1 & "&" & T1, "&")
For i = 0 To UBound(Q)
Z(Q(i)) = 0
Next
End If
Brr = xBook.Sheets("Layout Dwg").[A1].CurrentRegion
For i = 2 To UBound(Brr)
If Z.Exists(Brr(i, 2)) Then
Z(Brr(i, 1)) = Z(Brr(i, 1)) + Val(Brr(i, 3))
N = N + 1
For j = 1 To 3: Brr(N, j) = Brr(i, j): Next
End If
Next
If N > 0 Then Sheets("Layout Dwg").[K2].Resize(N, 3) = Brr: N = 0 Else MsgBox "Nothing2": GoTo 12
Brr = xBook.Sheets("Frame per Dwg").[A1].CurrentRegion
For i = 2 To UBound(Brr)
If Z(Brr(i, 1)) > 0 Then
N = N + 1
For j = 1 To 6: Brr(N, j) = Brr(i, j): Next
Brr(N, 5) = Brr(N, 5) * Z(Brr(i, 1))
End If
Next
If N > 0 Then Sheets("Frame per Dwg").[N2].Resize(N, 6) = Brr: N = 0
Brr = xBook.Sheets("Part List").[A1].CurrentRegion
For i = 2 To UBound(Brr)
If Z(Brr(i, 7)) > 0 Then
N = N + 1
For j = 1 To 13: Brr(N, j) = Brr(i, j): Next
Brr(N, 3) = Brr(N, 3) * Z(Brr(i, 7))
End If
Next
If N > 0 Then Sheets("Part List").[U2].Resize(N, 13) = Brr
12: If Re = True Then xBook.Close 0
End Sub |
|
|
用行動裝置瀏覽論壇學習很方便,謝謝論壇經營團隊
請大家一起上論壇來交流
|
|
|
|
|
- 帖子
- 582
- 主題
- 75
- 精華
- 0
- 積分
- 682
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-10-30
- 最後登錄
- 2026-4-13
|
7#
發表於 2025-10-8 16:29
| 只看該作者
本帖最後由 198188 於 2025-10-8 16:49 編輯
回復 198188
謝謝前輩發表此主題與範例
後學藉此帖練習陣列與字典,學習方案如下,請前輩參考
...
Andy2483 發表於 2025-10-8 14:54 
感謝前輩指點 |
|
|
|
|
|
|
|
- 帖子
- 582
- 主題
- 75
- 精華
- 0
- 積分
- 682
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-10-30
- 最後登錄
- 2026-4-13
|
8#
發表於 2025-10-9 17:30
| 只看該作者
回復 198188
謝謝前輩發表此主題與範例
後學藉此帖練習陣列與字典,學習方案如下,請前輩參考
...
Andy2483 發表於 2025-10-8 14:54 
前輩你好,檢視後,發現有兩點漏了提出,
Layout Dwg 需要加一個篩選條件 “批次”
Part List 需要增加一個資料: 篩選條件是,WO-No 欄F - 欄K 的各樣數據字母,舉例 WO-J057-022 �堶惘� "WS" 根據 Frame Per Dwg �堶悸熔楖佴牉鳩t有“WS”,在Part List 對應組裝號/加工件號 篩選出來 (只顯示各樣數據有的相關字母)數量也是兩個表的總數相乘 (如圖及附件) |
|
|
|
|
|
|
|
- 帖子
- 582
- 主題
- 75
- 精華
- 0
- 積分
- 682
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-10-30
- 最後登錄
- 2026-4-13
|
9#
發表於 2025-10-10 12:12
| 只看該作者
前輩你好,檢視後,發現有兩點漏了提出,
Layout Dwg 需要加一個篩選條件 “批次”
Part List ...
198188 發表於 2025-10-9 17:30 
Layout Dwg 批次問題已經解決。
Part List 補充方面 還沒解決
Frame per Dwg 表内欄B "組裝圖號" 含有 WO No �堶悸� "各樣數據" 欄F - 欄K 的英文字母,讀取 在Part List 欄G "對應組裝號/加工件號" 相同的"組裝圖號",及數量相乘。- For i = 2 To UBound(Brr)
- If Z.Exists(Brr(i, 2)) Then
- If Brr(i, 4) = Sheets("Read").[A2] Then
- Z(Brr(i, 1)) = Z(Brr(i, 1)) + Val(Brr(i, 3))
- N = N + 1
- For j = 1 To 4: Brr(N, j) = Brr(i, j): Next
- End If
- End If
- Next
- If N > 0 Then Sheets("Layout Dwg").[A2].Resize(N, 4) = Brr: N = 0 Else MsgBox "Nothing under the floor": GoTo 12
複製代碼 |
|
|
|
|
|
|
|
- 帖子
- 582
- 主題
- 75
- 精華
- 0
- 積分
- 682
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-10-30
- 最後登錄
- 2026-4-13
|
10#
發表於 2025-10-13 10:25
| 只看該作者
- Set Z = CreateObject("Scripting.Dictionary")
- xFile = "Data Base.xlsx"
- Set xBook = Workbooks(xFile)
- a = Sheets("WO No").Range("F2")
- b = Sheets("WO No").Range("G2")
- c = Sheets("WO No").Range("H2")
- d = Sheets("WO No").Range("I2")
- e = Sheets("WO No").Range("J2")
- f = Sheets("WO No").Range("K2")
- G = Sheets("Part List").Range("A1").CurrentRegion.Rows.Count + 1
- Brr = Sheets("Frame per Dwg").[A1].CurrentRegion
- For i = 2 To UBound(Brr)
- If Mid(Brr(i, 2), 1, 2) = a Or Mid(Brr(i, 2), 1, 2) = b Or Mid(Brr(i, 2), 1, 2) = c Or Mid(Brr(i, 2), 1, 2) = d Or Mid(Brr(i, 2), 1, 2) = e Or Mid(Brr(i, 2), 1, 2) = f Then
- Z(Brr(i, 2)) = Z(Brr(i, 2))
- N = N + 1
- For j = 1 To 6: Brr(N, j) = Brr(i, j): Next
- End If
-
- Next
-
- N = 1
- Arr = xBook.Sheets("Part List").[A1].CurrentRegion
- For i = 2 To UBound(Arr)
- If Z.Exists(Arr(i, 7)) Then
- N = N + 1
- For j = 1 To 13
- Arr(N, j) = Arr(i, j)
- Next j
- Arr(N, 5) = Arr(N, 5) * Z(Arr(i, 7))
- End If
- Next
- If N > 0 Then Sheets("Part List").Range("A" & G).Resize(N, 13) = Arr
複製代碼Layout Dwg 批次問題已經解決。
Part List 補充方面 還沒解決
Frame per Dwg 表内欄B "組裝圖 ...
198188 發表於 2025-10-10 12:12 
Part List 補充方面也解決,但是無法套入相同模組,需要獨立開一個模組。還有複製時,總是會複雜第一欄的名目。 |
|
|
|
|
|
|
|