'使用20楼的附件,中间数据在brr数组中可以在最后输出
'不一定正确,供参考
Option Explicit
Sub test()
Dim i, j, k, pos, n, t, arr, sht, ii, mark, m
pos = Split("3-2 4-3 5-4 6-5 7-6 8-7 10-8 11-9 12-10 14-11 15-12 16-13")
sht = Split("pc端店铺来源 无线端店铺来源")
mark = Split("PC端 无线端")
ReDim brr(1 To Rows.Count, 1 To 17)
For ii = 0 To UBound(sht)
With Sheets(sht(ii))
arr = .Range("a2:m" & .Cells(Rows.Count, "a").End(xlUp).Row + 1)
End With
For i = 1 To UBound(arr, 1) - 1
If Trim(arr(i, 2)) = "来源名称" Then
For j = i + 1 To UBound(arr, 1) - 1
n = n + 1: brr(n, 17) = mark(ii)
brr(n, 1) = Split(Split(arr(j, 1), "竞店入店来源对比-")(1), "_")(0)
brr(n, 2) = arr(i - 4, 3): brr(n, 9) = arr(i - 3, 3): brr(n, 13) = arr(i - 2, 3)
For k = 0 To UBound(pos)
t = Split(pos(k), "-"): brr(n, Val(t(0))) = arr(j, Val(t(1)))
Next
If Len(Trim(arr(j + 1, 2))) = 0 Then i = j: Exit For
Next
End If
Next i, ii
ReDim arr(1 To 3 * n, 1 To 9)
pos = Array(1, 2, 17, 3, 4, 5, 6, 7, 8, 1, 9, 17, 3, 0, 10, 11, 12, 0, 1, 13, 17, 3, 0, 14, 15, 16, 0)
For i = 1 To UBound(arr, 1) Step 3
n = (i - 1) / 3 + 1: m = 0
For j = i To i + 2
For k = 1 To UBound(arr, 2)
If pos(m) > 0 Then arr(j, k) = brr(n, pos(m))
m = m + 1
Next k, j, i
With Sheets("格式整理").[k2] '作比较用,店铺名称未作排序,自己排一下
.Resize(Rows.Count - 11, UBound(arr, 2)).ClearContents
.Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End With
End Sub |