各位高手,要根據Sheet1的批次
[attach]21208[/attach]
去Sheet2找實際儲位(就是Sheet2的標題列)
[attach]21209[/attach]
目前的巨集如下~可執行,但是資料量大時會找很久,想請教各位是不是有比較快的方法,謝謝!
Sub AA()
Z = Sheet1.[A65536].End(xlUp).Row
For ZZ = 2 To Z
For X = 1 To 48
For Y = 1 To 1000
If Sheet1.Cells(ZZ, 1) = Sheet2.Cells(Y, X) Then
Sheet1.Cells(ZZ, 4) = Sheet2.Cells(1, X)
End If
Next
Next
Next
End Sub
Option Explicit
Sub TEST()
Dim Brr, Y, i&, j%, xR As Range, Sh1 As Worksheet, Sh2 As Worksheet
Set Y = CreateObject("Scripting.Dictionary")
Set Sh1 = Sheets("Sheet1"): Set Sh2 = Sheets("Sheet2")
Set xR = Sh2.[A1].CurrentRegion: Brr = xR
For i = 1 To UBound(Brr)
For j = 1 To UBound(Brr, 2)
If Brr(i, j) <> "" Then Y(Brr(i, j)) = Brr(1, j)
Next
Next
Set xR = Range(Sh1.[A2], Sh1.Cells(Rows.Count, 1).End(3)): Brr = xR
For i = 1 To UBound(Brr)
Brr(i, 1) = Y(Brr(i, 1))
Next
xR.Offset(0, 3) = Brr
Set Y = Nothing: Set xR = Nothing: Set Sh1 = Nothing: Set Sh2 = Nothing
Erase Brr
End Sub作者: chen301222 時間: 2023-11-26 09:39
Sub FIND()
Dim arr, i, j, d As Object
Set d = CreateObject("Scripting.Dictionary")
With Sheets("sheet2")
arr = .[a1].CurrentRegion
For i = 1 To UBound(arr)
For j = 1 To UBound(arr, 2)
If arr(i, j) <> "" Then
d(arr(i, j)) = arr(1, j)
End If
Next j
Next i
End With
With Sheets("sheet1")
arr = .[a1].CurrentRegion
For i = 2 To UBound(arr)
If d.exists(arr(i, 1)) Then
arr(i, 4) = d(arr(i, 1))
End If
Next i
.[a1].CurrentRegion = arr
End With
End Sub作者: Andy2483 時間: 2023-11-28 08:19
Option Explicit
Sub TEST_1()
Dim Brr, Z, i&, A As Range, j&, xA As Range
Set Z = CreateObject("Scripting.Dictionary")
Set xA = [Sheet2!A1].CurrentRegion
For Each A In xA.Offset(1, 0).SpecialCells(2)
Z(A & "") = xA.Cells(1, A.Column) & ""
Next
Brr = Range([Sheet1!A2], 工作表1.Cells(Rows.Count, "A").End(3))
For i = 1 To UBound(Brr)
Brr(i, 1) = Z(Brr(i, 1) & "")
Next
[Sheet1!D2].Resize(UBound(Brr)) = Brr
End Sub作者: shuo1125 時間: 2023-11-28 14:47
' 遍歷 xA 中的每一個儲存格,排除標題
For Each A In xA.Offset(1, 0).SpecialCells(2)
' 在字典中添加項目,鍵為A 值為xA
Z(A.Value) = xA.Cells(1, A.Column).Value
Next A作者: Andy2483 時間: 2023-11-28 15:15
' ↓遍歷 xA 中的標題下方每一個非空格儲存格,
For Each A In xA.Offset(1, 0).SpecialCells(2)
' ↓在字典中添加項目,Key為A儲存格值 ,Item為A儲存格所在欄位標題列的標題值
' ↓A是通用型變數,在此處是物件(儲存格),所以要以A的值納入字典,所以要加.Value或加 & ""
Z(A.Value) = xA.Cells(1, A.Column).Value
Next A