代码如下。。。
会提取最后面的数据,连其他4列的一起处理了
Sub test()
Dim wb As Workbook, sht As Worksheet, sh As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("sheet1")
Set sh = wb.Sheets("sheet2")
arr = sht.[a1].CurrentRegion
crr = sh.[a1].CurrentRegion
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
s = arr(i, 2)
If Not d.exists(s) Then
d(s) = Array("'" & arr(i, 4), arr(i, 5), arr(i, 6), arr(i, 7), arr(i, 8))
Else
brr = d(s)
d(s) = Array(IIf(arr(i, 4) <> Empty, "'" & arr(i, 4), brr(0)), IIf(arr(i, 5) <> Empty, arr(i, 5), brr(1)), _
IIf(arr(i, 6) <> Empty, arr(i, 6), brr(2)), IIf(arr(i, 7) <> Empty, arr(i, 7), brr(3)), _
IIf(arr(i, 8) <> Empty, arr(i, 8), brr(4)))
End If
Next
For i = 2 To UBound(crr)
s = crr(i, 2)
If d.exists(s) Then
sh.Cells(i, 4).Resize(, 5) = d(s)
End If
Next
Beep
End Sub
|