|
代码如下。。。
Sub test()
Dim wb As Workbook, sht As Worksheet, sh As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("数据表")
Set sh = wb.Sheets("查询")
r = sht.Cells(sht.Rows.Count, 1).End(3).Row
c = sht.Cells(2, sht.Columns.Count).End(1).Column
arr = sht.Range(sht.[a2], sht.Cells(r, c))
r = sh.Cells(sh.Rows.Count, 1).End(3).Row
c = sh.Cells(2, sh.Columns.Count).End(1).Column
brr = sh.Range(sh.[a2], sh.Cells(r, c))
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
For j = 2 To UBound(arr, 2)
If arr(i, j) = tmpty Then
ss = arr(i, 1)
Else
s = arr(i, j)
If Not d.exists(s) Then
x = ss & arr(i, 1) & "|" & arr(1, j)
d(s) = x
Else
x = d(s)
d(s) = x & "|" & ss & arr(i, 1) & "|" & arr(1, j)
End If
End If
Next
Next
n = 0: x = 0
ReDim crr(1 To UBound(brr), 1 To 100)
For i = 2 To UBound(brr)
s = brr(i, 1)
If d.exists(s) Then
k = Split(d(s), "|")
n = n + 1
For j = 0 To UBound(k) Step 2
crr(n, j + 1) = k(j)
crr(n, j + 2) = k(j + 1)
x = Application.Max(x, j + 2)
Next
End If
Next
sh.[b3].Resize(r - 1, x) = crr
Set d = Nothing
Beep
End Sub
|
评分
-
1
查看全部评分
-
|