|
思路没问题,但目标 列和源数据的列顺序不一致,给你改了一下。- Sub 字典法复制数据() '//2023.3.22
- Dim arr, brr, d, crr
- Set d = CreateObject("Scripting.Dictionary")
- arr = Sheets("数据源").[a1].CurrentRegion
- crr = WorksheetFunction.Transpose(WorksheetFunction.Transpose(Sheets("数据源").Range("a1:e1")))
- For i = 2 To UBound(arr)
- s = arr(i, 1)
- d(s) = i
- Next
- With Sheets("目标表")
- brr = .[a1].CurrentRegion
- For i = 2 To UBound(brr)
- s = brr(i, 1)
- If d.exists(s) Then
- For j = 2 To UBound(brr, 2)
- k = WorksheetFunction.Match(brr(1, j), crr, 0)
- brr(i, j) = arr(d(s), k)
- Next
- End If
- Next
- .[a1].CurrentRegion = brr
- .[a1].CurrentRegion.Borders.LineStyle = 1
- End With
- End Sub
复制代码 |
|